Disabling macros.

E

EllenM

Hello,
I have a word document containing macros which run automatically when I
launch the document. Specifically, the macro displays a userform which
prompts the user to enter data that will go into the word file but saves a
copy of this word file with the changes. The original file is untouched. So
far so good.


Here is my dilemma: I do not want the macro to run each time I open the
copy of the original file. I found WordBasic.DisableAutoMacros at the
following link but do not know how or where to use it. Can I use this
command to disable auto-open macros from copies but keep the auto-open macros
enabled in the original file? Thanks.

http://word.mvps.org/FAQs/InterDev/DisableAutoMacros.htm
 
J

Jean-Guy Marcil

EllenM said:
Hello,
I have a word document containing macros which run automatically when I
launch the document. Specifically, the macro displays a userform which
prompts the user to enter data that will go into the word file but saves a
copy of this word file with the changes. The original file is untouched. So
far so good.


Here is my dilemma: I do not want the macro to run each time I open the
copy of the original file. I found WordBasic.DisableAutoMacros at the
following link but do not know how or where to use it. Can I use this
command to disable auto-open macros from copies but keep the auto-open macros
enabled in the original file? Thanks.

http://word.mvps.org/FAQs/InterDev/DisableAutoMacros.htm

Do you ever need the code to run when you open the original file?
Is this original file a document or a template (*.dot)
 
J

Jean-Guy Marcil

EllenM said:
The original file is a .doc file.

I think you should save the original as a template (*.dot).
Your original question stated:
"I do not want the macro to run each time I open the copy of the original
file." This is difficult because how should the code know when to run the
code and when not to?

If you have the code in a template, then move all your code in the
ThisDocument module, inside the "Private Sub Document_New()" sub. This way,
whenever a document is created from the template, the code will run. You will
need to modify the code because you do not need to do a "SaveAs" anymore
because you are not working from a *.doc anymore.
Whenever you just open the template, the code will not run. When you open a
document that was created in this way, even if they are linked to the
template, the code will not run becasue there is no code in the "Private Sub
Document_Open()" sub.
I think that what you have now is a difficult way to work (i.e. a *.doc
acting as a *.dot). It is much easier/safer to work with an actual *.dot.
Another advantage of working with the *.dot is that if you change the code,
you just need to change the template, all documents based on the template
will inherit the changes automatically. Otherwise, with your approach, you
will end up with a bunch of *.doc contianing old/wrong code.
 
F

fumei via OfficeKB.com

EllenM, you should listen to Jean-Guy on this. Using a .doc file as a
template is not generally a good idea at all. A real template file, a .DOT
file, is designed for just this kind of situation.

You can have your userform display with the creation of a new document, but
not when that new document is saved, then opened again. Which sounds exactly
what you are asking about.
 

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