MS Word AutoMacros and Scripting

Posted on 2011-05-06
Last Modified: 2012-05-11
I have created a template with AutoNew and AutoOpen macros.  The document works as expected by itself (creating a new doc based on the template triggers the AutoNew macro).  However, I cannot get it to work from a script.  I am using the line:

"c:\program files\microsoft office\office12\winword.exe" /t"C:\AFINETY\MACROS\WORD\AFINETY\Library\Marrketing\Project_Descriptions_List.dotm"

The template text is appearing in the new document, but the AutoNew doesn't trigger.

Am I missing a parameter or command. Is there a different way to start up Word based on a specific template?
Question by:Mighty-Jack
    LVL 76

    Expert Comment

    That is right. AutoNew (and Document_New) events do not fire for the first document.

    You could put a macro in the Normal template to make a new document, and call that with the /m switch

    "c:\program files\microsoft office\office12\winword.exe" /mNewPDLDoc
    Sub NewPDLDoc()
        Documents.Add "C:\AFINETY\MACROS\WORD\AFINETY\Library\Marrketing\Project_Descriptions_List.dotm"
    End Sub

    Open in new window


    Author Comment


    I understand what you are saying.  I am disappointed that the script will not run the automacro.  Starting the new document from within Word would certainly solve the macro triggering problem.  However, I need to explain my particular challenge more clearly.

    I have created a template that the attorneys need to use for marketing.  Our attorneys are a bit of a special case (some semi-luddites), so the director wants to make it as easy for them as possible to start a new marketing document.

    Initially, I simply installed a folder on their desktops that contained shortcuts to the templates, which when activated will create a new a document, and any automacros in the templates will trigger.

    Now, though, there is a concern that the templates on the machine may not have been updated before the attorney creates a new document.  (Templates are updated whenever a user logs into the network, but some attorneys leave their machine on.  They can also be updated by running a cmd file as the administrator.)  So, essentially I need a one-click (or double-click) way of 1) running the cmd file that updates the macros, and 2) starting a new Word document based on the specified template in a way that will trigger the automacros.

    I have attached to this post the script I am currently testing.  The initial settings at the top were copied from the our login script, which is what calls up the macro-updating cmd file when a user logs in.

    Is it possible to script activating a shortcut?  If that is possible, that would solve the problem.

    And now that I have explained the ultimate goal, is there possibly a better option for accomplishing both steps other than a Windows script?

    Thank you for your help on this issue.
    LVL 76

    Accepted Solution

    I suggest that you keep the templates on a server share. There is a Word option (Office button> Word Options...> Advanced>File Locations>Workgroup templates). If that is set to the folder, the templates in it will be listed under 'My templates...' in Word's 'New Document' dialogue.

    Incidentally, don't be tempted to set the 'User templates' location to a shared folder, or there will be problems with the Normal template.

    I was never very good at DOS commands, but I suppose that you could launch a VBScript which could open Word and then open the particular document or template with the macro that you want to run automatically.

    Author Comment

    I think your last suggestion would work.  Unfortunately, I am restricted by the preferences of our network integrators on template location.  

    Really, the only issue is making sure that their template is updated before they create a new document.  The desktop shortcut and our template selection process within Word do work; they create a new document based on the template and the AutoNew macro triggers.

    I think in the case of our relatively small office, I will just make sure the attorney workstations are updated when I post an updated template, which should not happen too frequently.  Low-tech, yes, but in the end I think it is better than any process that will just confuse the less tech-inclined attorneys.

    I will accept your last suggestion as a solution.  Thanks.

    Author Closing Comment

    Solution not a good fit for the way our network is configured, but it is a good solution.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    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

    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…
    Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
    The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
    This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.

    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

    11 Experts available now in Live!

    Get 1:1 Help Now