Auto Run Macros

Posted on 2008-10-24
Medium Priority
Last Modified: 2012-05-05
My secretaries at work asked me if there was a way to display the full path of a file in the title bar in Word 2007. I found a macro on this site, that will let me do that.

Sub ChangeCaption()
    ActiveWindow.Caption = ActiveDocument.FullName
End Sub

However, I would like for that macro to start whenever they open any document. I found code somewhere that stated that I needed to add a DocumentSub to my code. I'm a beginner when it comes to coding and macros so I am unsure where to put the code in. If someone could help me by displaying the entire above code with the autorun code included, that would be a tremendous help. Thanks.
Question by:Smp351
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 76

Accepted Solution

GrahamSkan earned 1500 total points
ID: 22798121
You have a couple of choices.
A sub called AutoOpen in a code module that has been inserted via Insert/Module in the VBA editor menu.

Or you can have one called Document_Open in the ThisDocument module.

To catch all occurrences, the code should be in the Normal template.

Author Comment

ID: 22798137
Thank you for the quick response but where do I put that? I really have no experience with coding so I would not know what to do with your suggestions.
LVL 76

Expert Comment

ID: 22798404
Open the VBA editor with Alt + F11.

The top left pane will list the open projects. There dhoul alway be one called Normal. If you open this with the + sign next to it and then the Microsoft Word Objects folder, you will see the ThisDocument module. Double click on it to open the code pane on the right.
You will see that the left-hand box has two items -  (General) and Document. Choose Document and it will volunteer the Document_New event and put an empty procedure for it in the code pane. Ignore that and choose the 'Open' event procedure from the right-hand dropdown. You will get a similar empty procedure . You can put your code in there.
You don't generally need to save it, because the Normal template is routinely saved when Word is closed.
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


Author Comment

ID: 22798665
I did exactly as you said and when I go to open a new document, I get the debugger for Visual Basic. It says Compile Error: Unexpected End Sub. I'll attach a file with what my code looks like. Sorry, I'm just not great with coding.


Author Comment

ID: 22798773
Just to state, I know there should be two End Subs at the end. I deleted one by accident. Even when I add the 2nd one back, I still get the error.
LVL 76

Assisted Solution

GrahamSkan earned 1500 total points
ID: 22798837
It would be better if you just pasted the code.
It is taking ages for your bmp to load.

Remove the Sub ChangeCaption line

Author Comment

ID: 22798920
Sorry about that Graham. Removing the sub worked. Thank you guys very much. I really appreciate it.

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you ever need to create a 20 page Word document for some testing purpose? Are you tired of copying & pasting old boring "lorem ipsum" text over and over again, increasing font size and line space in order to make the document 20+ pages long? Look…
Nice table. Huge mess. Maybe this was something you created way back before you figured out tabs or a document you received from someone else. Either way, using the spacebar to separate the columns resulted in a mess. Trying to convert text to t…
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question