• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 293
  • Last Modified:

MS Word AutoMacros and Scripting

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?
0
Dave Kong
Asked:
Dave Kong
  • 3
  • 2
1 Solution
 
GrahamSkanRetiredCommented:
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

0
 
Dave KongAuthor Commented:
Graham:

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.
UpdateTemplatesOpenProjDescr.cmd
0
 
GrahamSkanRetiredCommented:
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.
0
 
Dave KongAuthor Commented:
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.
0
 
Dave KongAuthor Commented:
Solution not a good fit for the way our network is configured, but it is a good solution.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now