Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


MS Word AutoMacros and Scripting

Posted on 2011-05-06
Medium Priority
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:Dave Kong
  • 3
  • 2
LVL 77

Expert Comment

ID: 35710456
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

by:Dave Kong
ID: 35710592

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 77

Accepted Solution

GrahamSkan earned 375 total points
ID: 35711283
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

by:Dave Kong
ID: 35725660
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

by:Dave Kong
ID: 35725667
Solution not a good fit for the way our network is configured, but it is a good solution.

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.
Suggested Courses

580 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