Run macro on template open

P

Patrick Simonds

How do you get a macro to run when a template is opened? The code below
works fine in a regular document, but after I saved the document as a Macro
Enabled Template, it does not run when the template is opened.

Private Sub Document_Open()

UserForm1.Show

End Sub
 
C

Cindy M -WordMVP-

Hi Patrick,

If you actually *open* a template, this macro would run. It should also run if
a document that was created from the template is opened.

But if you mean, how to get a macro to run when a new document is created, use
the Document_New event, instead :)
How do you get a macro to run when a template is opened? The code below
works fine in a regular document, but after I saved the document as a Macro
Enabled Template, it does not run when the template is opened.

Private Sub Document_Open()

UserForm1.Show

End Sub

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
P

Patrick Simonds

Sorry I do not know what I am doing wrong here. I have tried:

Private Sub Document_Open()

UserForm1.Show

End Sub


and


Private Sub Document_New()

UserForm1.Show

End Sub

But still the Macro does not run. I have put this code under Microsoft Word
Objects -- This document. I click on New -- My Templates and then click on
the Template to run it. This is so simple to do in Excel but I seem to be
totally lost here.
 
C

Cindy M -WordMVP-

Hi Patrick,
Sorry I do not know what I am doing wrong here. I have tried:

Private Sub Document_Open()

UserForm1.Show

End Sub


and


Private Sub Document_New()

UserForm1.Show

End Sub

But still the Macro does not run. I have put this code under Microsoft Word
Objects -- This document. I click on New -- My Templates and then click on
the Template to run it. This is so simple to do in Excel but I seem to be
totally lost here.
Sub Document_New should run - assuming the macro security is allowing VBA code
execution. Can you describe what you mean by "Macro Enabled Template" (in your
original message)? Which version of Word are we looking at, here?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
P

Patrick Simonds

Thank you for all your time.

I found my error. When I started this I did all my work on a normal document
(not a template) and when I was done I saved as a Template, so all my code
was under Normal not under TemplateProject. To answer your other question:

"Can you describe what you mean by "Macro Enabled Template""

I am running the Beta version of office 2007 and you same documents with
macros as "Macro Enabled"
 
C

Cindy M -WordMVP-

Hi Patrick,
I found my error. When I started this I did all my work on a normal document
(not a template) and when I was done I saved as a Template, so all my code
was under Normal not under TemplateProject.
Yep, that will make a difference :)
I am running the Beta version of office 2007
I thought that might be it... You really do have to remember to mention this in
every new question, since there's no guarantee someone will have read previous
questions, or even remember, if they did.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

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