AutoExec to open to specific document

mipendance
StarLounger
Posts: 72
Joined: 18 Aug 2011, 19:39

AutoExec to open to specific document

Post by mipendance »

Hello -

Need help with AutoExec macro in World. Have Microsoft Office 365. Would like it to open to a specific document. Thank you

User avatar
HansV
Administrator
Posts: 69487
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: AutoExec to open to specific document

Post by HansV »

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:

Code: Select all

Sub AutoExec()
    Documents.Open "C:\Word\MyDocument.docx"
End Sub
You have to change the path and filename, of course.
Regards,
Hans

mipendance
StarLounger
Posts: 72
Joined: 18 Aug 2011, 19:39

Re: AutoExec to open to specific document

Post by mipendance »

Thank you so very much, and for your quick response!

User avatar
Charles Kenyon
3StarLounger
Posts: 339
Joined: 10 Jan 2016, 15:56
Location: Madison, Wisconsin

Re: AutoExec to open to specific document

Post by Charles Kenyon »

:sad: I beg to differ. :sad:
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
Is this a log file of some sort? You may be better off with Documents.New and a template if it is not.
Attorney Charles Kenyon

Templates in Microsoft Word http://www.addbalance.com/usersguide/templates.htm
Modifying the QAT http://addbalance.com/word/QATmodification.htm

User avatar
HansV
Administrator
Posts: 69487
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: AutoExec to open to specific document

Post by HansV »

Sorry, Charles - I work with Excel much more often than with Word. You are correct, of course.
Regards,
Hans

User avatar
Charles Kenyon
3StarLounger
Posts: 339
Joined: 10 Jan 2016, 15:56
Location: Madison, Wisconsin

Re: AutoExec to open to specific document

Post by Charles Kenyon »

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 http://www.addbalance.com/usersguide/templates.htm
Modifying the QAT http://addbalance.com/word/QATmodification.htm