How do get macro in MS Word to start when document is loaded?

Posted on 2005-04-22
Last Modified: 2013-12-25
I have written a macro VBA in Microsoft Word. When I open the document that contains the macro, how can I get a macro to run automatically after document has loaded?
Question by:gar7
    LVL 10

    Accepted Solution

    Hi, gar7.

    If your macro is "Macro1" you could do the following:

    1)   Do Alt-F11 when your Word doc is open to display the Microsoft Visual Basic code window.

    2)   In the left-hand Project-Normal box expand "Microsoft Word Objects" and double-click "ThisDocument."

    3)   On the top-left dropdown of the "Normal - ThisDocument (Code)" window, click "Document."  On the right-hand dropdown click "Open."

    4)   In the Private Sub Document-Open() method, enter the following code:

         Call Macro1

    LVL 10

    Expert Comment

    Sorry--I'm used to applying code to all Word docs in my library at once.

    In step 1 above, replace "left-hand Project-Normal box expand" with "Project window expand Project(Document1) and ".
    In step 3 above, replace "Normal - ThisDocument(Code)" with "Document1 - ThisDocument(Code)".

    That will only apply this coding to the current Word document, not every one you open as controlled by Normal.

    Author Comment

    edwardiii - Thabks for the help. You hit it right on the head!!

    LVL 10

    Expert Comment

    Glad to have helped:)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
    Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    760 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

    12 Experts available now in Live!

    Get 1:1 Help Now