Menu Macro doesn't work when .Doc saved as .Dot

M

Microsmith

Hello,

I've written VBA code for a macro that executes when the document is opened.
The Macro sets up a custom menu on the menu bar. The macro depends on a
text file stored in another directory. If the text file exists, one ste of
menus is created. If the text file doesn't exist, a different menu is
created. The macro executes flawlessly when I save it as a normal .doc
document. However, when I save it as a .dot the macro doesn't work when I
close Word and then reopen. If I remove the provision in the macro that
checks the existence of the text file, the menu macros execute fine wether
its saved as a .doc or .dot.

Any suggestions why the macro would work in a .doc but not a .dot document?

Thanks
Microsmith
 
D

David Sisson

How are you opening the template? File -> New

Open event macros don't work when stored in .dot as they assume they
will be activated upon File->New.

See help file on Open event
'---------------------
Open Event

Applies ToExampleSpecificsOccurs when a document is opened.

Private Sub Document_Open()
Remarks
If the event procedure is stored in a template, the procedure will run
when a new document based on that template is opened and when the
template itself is opened as a document.

For information about using events with the Document object, see Using
Events with the Document Object.

Example
This example displays a message when a document is opened. (The
procedure can be stored in the ThisDocument class module of a document
or its attached template.)

Private Sub Document_Open()
MsgBox "This document is copyrighted."
End Sub
 
M

Microsmith

David,

You make a good point about open event procedures. I reviewed my code and
found a couple of miscodings. It seem to be working now. Thanks for
replying!

Microsmith
 
M

Microsmith

Here's a follow-up to my post. After experimenting with various macros using
open event and new event procedures, what I learned is that the event macros
were not being executed when they wetre opened as part of a global add-in
template. After further research, I learned about Auto Macros (see Auto
Macros in Help). By substituting AutoExec as my macro name in a new module
in place of the open event prtocedure, and substituting AutoClose as my macro
name in the same new module in place of the close event procedure, the macros
worked as intended whenever I opened Word (The document template was saved as
a .dot document in the ApplicationData>Microsoft>Word>STARTUP Folder)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top