Solved

Auto Run Macros

Posted on 2008-10-24
7
747 Views
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.
0
Comment
Question by:Smp351
  • 4
  • 3
7 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
Comment Utility
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.
0
 

Author Comment

by:Smp351
Comment Utility
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.
0
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
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.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:Smp351
Comment Utility
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
0
 

Author Comment

by:Smp351
Comment Utility
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.
0
 
LVL 76

Assisted Solution

by:GrahamSkan
GrahamSkan earned 500 total points
Comment Utility
It would be better if you just pasted the code.
It is taking ages for your bmp to load.


Remove the Sub ChangeCaption line
0
 

Author Comment

by:Smp351
Comment Utility
Sorry about that Graham. Removing the sub worked. Thank you guys very much. I really appreciate it.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction Authors who set out to write any sort of lengthy piece for online submission—be it a long question or comment on a technical form, an article, or a substantial blog entry—often find it useful to work up a draft in an editor other t…
Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now