Link to home
Start Free TrialLog in
Avatar of Smp351
Smp351

asked on

Auto Run Macros

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.
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Smp351
Smp351

ASKER

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.
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.
Avatar of Smp351

ASKER

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.

Visual-Basic.bmp
Avatar of Smp351

ASKER

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.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Smp351

ASKER

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