SELECT DISTINCT FROM IHR WHERE filename = 'temp.docx' Select Distinct Item From IHR where filename istemp.docx 'select distinct item based on filename ' StrMsg = "Error " & Err.Number & " (" & Err.Description _
Set docCur = (FileName:=strDocPath & strDocName, _ĭebug.Print "FullName: " & docCur.FullNameĭebug.Print "ReadOnly: " & docCur.ReadOnlyĭntent = ntent & vbCrLf & CStr(Now)ĪppCur.Quit SaveChanges:=wdDoNotSaveChanges Public Sub EditWordDocs()Ĭonst cstrFolder As String = "C:\share\testdocs\"
Cell(rsIt.AbsolutePosition + 2, 4).Range.InsertAfter strPr StrPr = strPr & " " & rsPr.Fields(4).Value If Not (rsPr.BOF And rsPr.EOF) = True Then Set rsPr = dbCur.OpenRecordset(strSQL, dbOpenDynaset) StrSQL = "Select Distinct Precaution From IHR where item is" 'select distinct precaution based on item Cell(rsIt.AbsolutePosition + 2, 3).Range.InsertAfter strHz StrHc = strHz & " " & rsHz.Fields(2).Value If Not (rsHz.BOF And rsHz.EOF) = True Then Set rsHz = dbCur.OpenRecordset(strSQL, dbOpenDynaset) StrSQL = "Select Distinct Hazard From IHR where item is" Cell(rsIt.AbsolutePosition + 2, 2).Range.InsertAfter strHc StrHc = strHc & " " & rsHc.Fields(2).Value If Not (rsHc.BOF And rsHc.EOF) = True Then Set rsHc = dbCur.OpenRecordset(strSQL, dbOpenDynaset) StrSQL = "Select Distinct Hazcard From IHR where item is" Cell(rsIt.AbsolutePosition + 2, 1).Range.InsertAfter rsIt.Fields(1).Value If Not (rsIt.BOF And rsIt.EOF) = True Then Set rsIt = dbCur.OpenRecordset(strSQL, dbOpenDynaset) StrSQL = "Select Distinct Item From IHR where filename is"
Cell(1, 4).Range.InsertAfter "Precaution" Set rngCcCur = docCur.ContentControls(6).RangeĪ Range:=rngCcCur, NumRows:=1, NumColumns:=4 Set docCur = (FileName:=strDocPath & strDocName, ReadOnly:=False, Visible:=False) Set dlgCur = Application.FileDialog(msoFileDialogFolderPicker)
CANNOT OPEN NEW DOCUMENT IN WORD CODE
The code is also kind of clunky with the multiple recordsets, if anyone has any better ideas would love to here them. Sorry for incredibly long code block - I felt it was important to show everything so that it was easier to find the problem. I need to be able to edit the document (that is the whole point of the code). Word then shows a file locked for editing/ open read only prompt. Then, click “OK”.The following code runs as far as the marked line.
CANNOT OPEN NEW DOCUMENT IN WORD WINDOWS
To use the Run dialog box to open the most recent document in Word, press the Windows key+R and enter the same command ( winword.exe /mfile1 ) in the Open box. To use the Search/Cortana box, click the Cortana search icon on the Taskbar (or the Search icon, if you’ve disabled Cortana) and enter the following into the box: winword.exe /mfile1
In that case, you can open the most recent document in Word using either the Search/Cortana box or the Run dialog box. Maybe you don’t want to add yet another shortcut to your desktop. Option Two: Use the Run Dialog Box or the Search/Cortana Box In the Target edit box, put the cursor after the path currently there (preserving the quotes), and enter a space and then the following: /mfile1Ĭhange the title of the shortcut to indicate it will open the last opened document.įrom now on, you can double-click this shortcut to open the most recent document, whatever it may be. Right-click on the new shortcut and select Properties. Right-click on the WINWORD.EXE file and go to Send to > Desktop (create shortcut).