Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems running code in Startup.dot

Status
Not open for further replies.

bodmin

Technical User
Apr 1, 2004
98
GB
Hi guys,

I am having some trouble getting an Auto macro to run from either the Startup.dot global template or the normal.dot global template.

I currently have the following code in the ThisDocument section of either template as a proof that the function is being run.

Sub AutoExec()
MsgBox ("Running Auto Macro")
End Sub

So far it appears that whenever I actually directly open these templates for editing the code is executed and the message box displayed. However when I open any other document the macro is not automatically run, it is available in the list of macros but is not actually being executed.

Has anybody got any ideas as to why the macro is not automatically executing and a way that I can get this to happen.

many thanks in advance
Andi
 
Just been doing some more investigation and I have noticed that documents that do not have a reference to a template other than normal.dot or startup.dot appear to be not executing the startup code that is located in the global templates.

For example I have 2 documents one has no template reference and the other references a template "Design". When I open the document with no template reference the normal.dot startup code is executed and the message displayed. Whereas when I open the document with the Design template reference no code is executed from the normal.dot template but I can browse to this macro and manually execute.

Is there someway to make normal.dot macros to automatically run when the document has been produced from a different custom template. Perhaps by normal.dot dynamically creating sub routines in referenced template??

Any ideas would be great, many thanks in advance

Andi
 
I'm not entirely sure what you're asking - or what you're actually seeing. Do note the following, but can you give a little more specific detail.

1. All documents have templates.
2. AutoExec macros in global templates should run when the templates are loaded at Word startup.
3. If you want code to run when a document is opened you should use AutoOpen or Document_Open routines.

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
The standard place for auto macros with names starting with 'Auto' is a standard module. They are recognised either by module name or procedure name.
For details, search for 'auto macros' in word vba help file.

combo
 
Hi guys,

I have now corrected the problem was a syntax error in my sub declaration.

many thanks for the help.

For info I ended up using the AutoOpen sub, with the code stored in the normal.dot template, with the corrected function this is now being executed when a document was opened regardless of whether the document was originally based on the normal.dot template or any other template.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top