Hello -
Need help with AutoExec macro in World. Have Microsoft Office 365. Would like it to open to a specific document. Thank you
AutoExec to open to specific document
-
- StarLounger
- Posts: 73
- Joined: 18 Aug 2011, 19:39
-
- Administrator
- Posts: 78235
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: AutoExec to open to specific document
You can make Word open one or more documents automatically without using a macro: store the documents in Word's startup folder (by default C:\Users\<username>\AppData\Roaming\Microsoft\Word\STARTUP).
If you want to use an AutoExec macro, it would look like this:
You have to change the path and filename, of course.
If you want to use an AutoExec macro, it would look like this:
Code: Select all
Sub AutoExec()
Documents.Open "C:\Word\MyDocument.docx"
End Sub
Best wishes,
Hans
Hans
-
- StarLounger
- Posts: 73
- Joined: 18 Aug 2011, 19:39
Re: AutoExec to open to specific document
Thank you so very much, and for your quick response!
-
- 4StarLounger
- Posts: 596
- Joined: 10 Jan 2016, 15:56
- Location: Madison, Wisconsin
Re: AutoExec to open to specific document
I beg to differ.
Putting a document in the Word Startup Folder does nothing. This is different from Excel, I believe.
http://addbalance.com/word/startup.htm
Putting a template in that folder loads it as an Add-In.
http://www.addbalance.com/usersguide/te ... htm#Global
An AutoExec macro only works in templates and only when they are loaded as global templates.
https://wordmvp.com/FAQs/MacrosVBA/Appl ... Events.htm
The idea of an AutoExec macro is to have it run when Word starts.
If in a template, and you manually load the template as an Add-In (rather than having it in the Startup Folder) it will run when the template is loaded. -- If in the Startup folder, the template is loaded when Word starts, thus the macro runs when Word starts.
(by definition, the Normal template is a global template, loaded when Word starts -- it should not be in the Startup Folder but in the User Templates folder)
I believe that the following in an AutoExec macro will open the document. FullName includes the full path.
Is this a log file of some sort? You may be better off with Documents.New and a template if it is not.
Putting a document in the Word Startup Folder does nothing. This is different from Excel, I believe.
http://addbalance.com/word/startup.htm
Putting a template in that folder loads it as an Add-In.
http://www.addbalance.com/usersguide/te ... htm#Global
An AutoExec macro only works in templates and only when they are loaded as global templates.
https://wordmvp.com/FAQs/MacrosVBA/Appl ... Events.htm
The idea of an AutoExec macro is to have it run when Word starts.
If in a template, and you manually load the template as an Add-In (rather than having it in the Startup Folder) it will run when the template is loaded. -- If in the Startup folder, the template is loaded when Word starts, thus the macro runs when Word starts.
(by definition, the Normal template is a global template, loaded when Word starts -- it should not be in the Startup Folder but in the User Templates folder)
I believe that the following in an AutoExec macro will open the document. FullName includes the full path.
Code: Select all
Documents.Open FullName
Attorney Charles Kenyon
Templates in Microsoft Word
Modifying the QAT
The Importance of Styles in Microsoft Word
Templates in Microsoft Word
Modifying the QAT
The Importance of Styles in Microsoft Word
-
- Administrator
- Posts: 78235
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: AutoExec to open to specific document
Sorry, Charles - I work with Excel much more often than with Word. You are correct, of course.
Best wishes,
Hans
Hans
-
- 4StarLounger
- Posts: 596
- Joined: 10 Jan 2016, 15:56
- Location: Madison, Wisconsin
Re: AutoExec to open to specific document
Glad to be able to help. Your knowledge of Word vba exceeds mine and I appreciate the forum.
Attorney Charles Kenyon
Templates in Microsoft Word
Modifying the QAT
The Importance of Styles in Microsoft Word
Templates in Microsoft Word
Modifying the QAT
The Importance of Styles in Microsoft Word