0
votes

I was having requirement to run the Macro when we open the document. For that purpose i have created .Dotm template with AutoOpen method. Problem is it doesn't execute. When i add the AutoOpen macro in Normal file it works perfectly.

We don't want to add the AUtoOpen code in Normal.dotm file. How can we achieve the same using different Template file.

3

3 Answers

1
votes

I had exactly the same problem. I had 2 separate .dotms with AutoOpen modules that were not auto opening on XP or Win7 x64 both with Office 2010. I subsequently noticed that all my Subs in the AutoOpen module were Private. Hmmmmm. Made my Main Sub Public, left all other Subs Private, and both of them now AutoOpen. Maybe this will help.

0
votes

"For that purpose i have created .Dotm template with AutoOpen method."

Create new documents with this NotNormalWithAutoOpenMethod.Dotm with File | New.

For an existing document, create a new document based on NotNormalWithAutoOpenMethod.Dotm. Copy the contents of the existing document into the new blank document. Save and Close. Upon reopening the new document, the code should run.

0
votes

Wasn't me, but I'm guessing you got downvoted because you haven't said what you've tried, what version of Word you're using, or what OS you're on. All of those things are useful in diagnosing the issue.

I'm also guessing that you can not simply save the macro to whatever document you want to run it in, because that should be trivial. Am I correct?

If so, I am trying to do something very similar using Word 2010 on Windows 7 64-bit, but I can't get it to work yet either. The document I need to open is auto-generated from pandoc and is opened in compatibility mode, so perhaps that's my issue. If that's not the case for you, some of the things I've tried might help you.

  1. Use the /t option from the command line: start winword /tmacros.dotm document.docx
  2. If that doesn't work, try adding the /m option as well: start winword /tmacros.dotm /mAutoOpen document.docx.
  3. Instead of naming the macro AutoOpen, try AutoExec or Document_Open.

Note: there is no space between the /t or /m options and the filenames. I've also tried the full path to winword.exe instead of start winword but that didn't make a difference.

Hope this helps, good luck! And please post the solution back here if you figure it out on your own.

Sources:

Command line switch: http://support.microsoft.com/kb/290961

AutoExec/AutoOpen: http://support.microsoft.com/kb/286310