I have the following code to open the guide for the Excel Workbook application that I developed:
Sub OpenManual() 'Word.Application.Documents.Open "\\filePath\FormFlow To MSExcel\FeedSampleReport-Manual.docx" Dim objWord As Object Set objWord = CreateObject("Word.Application") objWord.Visible = True objWord.Documents.Open "\\filePath\FormFlow To MSExcel\FeedSampleReport-Manual.docx" End Sub
This gives me 2 questions:
- The document opens, but in the background. The user does not know that the document was opened if they do not know to check Microsoft Word on the taskbar.
- When I try to close a document document, I get: This file is being used by another application or user. (C: \ Users \ Me \ AppData ... \ Normal.dotm)
When I click ok in this dialog, I get the "Save As" screen.
If I canceled this and try to close an empty instance of Microsoft Word, I get:
Changes have been made that affect the global Normal template. Do you want to save these changes?
Then, if I click No, everything will finally close.
Can someone help me with these two issues? Do I need to somehow free an object? Never seen this before.
EDIT
After using the @ Layman-Coders method:
Sub OpenManual() 'Word.Application.Documents.Open "\\filePath\FormFlow To MSExcel\FeedSampleReport-Manual.docx" 'Open an existing Word Document from Excel Dim objWord As Object Set objWord = CreateObject("Word.Application") objWord.Visible = True ' Should open as the forefront objWord.Activate 'Change the directory path and file name to the location 'of the document you want to open from Excel objWord.Documents.Open "\\filePath\FormFlow To MSExcel\FeedSampleReport-Manual.docx" objWord.Quit Set objWord = Nothing End Sub
When I have another Word document open and click the button, the following will happen:
- At the initial stage, the manual opens, but I immediately get
This file is in use by another application or user. (C:\Users\Me\AppData\...\Normal.dotm) This file is in use by another application or user. (C:\Users\Me\AppData\...\Normal.dotm) - I click OK and I get the Save As dialog.
- Cancel the “Save As” dialog and present my “Guide” document.
- When I click the "Red X" button to close the document, I get
Changes have been made that affect the global template, Normal. Do you want to save those change? Changes have been made that affect the global template, Normal. Do you want to save those change? I click "No" and the document closes.
If this document is the first instance of the word that I open:
- The document opens.
- As soon as the code hits the
objWord.Quit line, the document closes immediately.
I just want the document to come to the forefront, allowing users to view the Guide for help when they need it, and let them close the document as they see fit.