Macro runs automatically on opening template?

C

Claudia

I've created a form with a macro to take the user through
the form with inputboxes and yes/no message boxes. It
works great, but I'd like the macro to run automatically
when the user pulls up the template. I believe all of
the users in our group have their macro security settings
set to low. We use Word 2003. When I open this same
template on my home computer that has Word 2000, the
macro runs automatically on opening the template. Any way
to get this to work with Word 2003?
 
J

Jonathan West

Claudia said:
I've created a form with a macro to take the user through
the form with inputboxes and yes/no message boxes. It
works great, but I'd like the macro to run automatically
when the user pulls up the template. I believe all of
the users in our group have their macro security settings
set to low. We use Word 2003. When I open this same
template on my home computer that has Word 2000, the
macro runs automatically on opening the template. Any way
to get this to work with Word 2003?

Give the macro the name "AutoNew"

For more information, take a look at this article

Running a macro automatically when a document is created, opened or closed
http://word.mvps.org/FAQs/MacrosVBA/DocumentEvents.htm
 
C

Charles Kenyon

Your security settings should be set to medium unless you have no access to
the Internet or outside documents.

If your template is in your workgroup templates folder and the security
settings are set to accept macros from that source, the macro should run
without problems.

You want the macro to run upon the creation of a new document from the
template, not upon opening the template. Opening a template is an incorrect
way to use one.

Also, you may want to look into using a UserForm rather than a bunch of
pop-ups. There is a good tutorial on creating one on the userform FAQ on the
MVP FAQ site.
 
C

Claudia

Charles said:
Also, you may want to look into using a UserForm rather than a bunch of
pop-ups. There is a good tutorial on creating one on the userform FAQ on the
MVP FAQ site.

I followed the instructions for creating a UserForm to
the letter, but I'm getting compile errors when it runs.
It highlights "Range" when giving me the error message.
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < Claudia > écrivait :
In this message, < Claudia > wrote:

|| Charles Kenyon wrote:
||
||| Also, you may want to look into using a UserForm rather than a bunch of
||| pop-ups. There is a good tutorial on creating one on the userform FAQ on
the
||| MVP FAQ site.
||
|| I followed the instructions for creating a UserForm to
|| the letter, but I'm getting compile errors when it runs.
|| It highlights "Range" when giving me the error message.

If you had followed the instructions to the letter, you would not be have
received an error message.

So, either you have a typo or you added/modified some code. We cannot tell
you what is wrong without looking at the code.
Post the code stating which line generates the error.

Don't forget that progrmamming, even VBA, is an exact science. One misplaced
space, comma, dot or character will cause trouble.
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
G

Guest

Jean-Guy patiently explained:
-----Original Message-----
So, either you have a typo or you added/modified some code. We cannot tell
you what is wrong without looking at the code.
Post the code stating which line generates the error.

Well, here ya go (below) - ".Range_" is being
highlighted, I guess, because I need a range? However,
nothing is mentioned in the tutorial as to how I figure
what the range is. The error message says "Method or Data
Member Not Found." Then, I tried adding "Paragraphs (1)"
and "Paragraphs (2)" as well as "Bookmarks" after
each .Range_ per samples in the Help files, identifying
the location for each bookmark. That didn't work either.

Private Sub CommandButton1_Click()
With ActiveDocument
.Bookmarks("Text1").Range_
.InsertBefore TextBox1
.Bookmarks("Text2").Range_
.InsertBefore TextBox2
End With

UserForm1.Hide
End Sub
Don't forget that progrmamming, even VBA, is an exact science. One misplaced
space, comma, dot or character will cause trouble.

Yes, I know.
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < (e-mail address removed) > écrivait :

|| Jean-Guy patiently explained:
||
||| -----Original Message-----
||| So, either you have a typo or you added/modified some code. We cannot
tell
||| you what is wrong without looking at the code.
||| Post the code stating which line generates the error.
||
|| Well, here ya go (below) - ".Range_" is being
|| highlighted, I guess, because I need a range? However,

This range that you speak of is the range of text defined by the bookmark
named in the brackets.

|| nothing is mentioned in the tutorial as to how I figure
|| what the range is. The error message says "Method or Data
|| Member Not Found." Then, I tried adding "Paragraphs (1)"

Yes, because "Range_" is not a known method/function/property.
"Range" is on the other hand!

|| and "Paragraphs (2)" as well as "Bookmarks" after
|| each .Range_ per samples in the Help files, identifying
|| the location for each bookmark. That didn't work either.
||
|| Private Sub CommandButton1_Click()
|| With ActiveDocument
|| .Bookmarks("Text1").Range_
|| .InsertBefore TextBox1
|| .Bookmarks("Text2").Range_
|| .InsertBefore TextBox2
|| End With
||
|| UserForm1.Hide
|| End Sub
||
|||
||| Don't forget that progrmamming, even VBA, is an exact science. One
misplaced
||| space, comma, dot or character will cause trouble.
||
|| Yes, I know.

What did I tell you about misplaced spaces and such! lol

Change
.Bookmarks("Text1").Range_
.InsertBefore TextBox1
.Bookmarks("Text2").Range_
.InsertBefore TextBox2
to
.Bookmarks("Text1").Range _
.InsertBefore TextBox1
.Bookmarks("Text2").Range _
.InsertBefore TextBox2
with a space before the underscore. A space followed by an underscore tells
the compiler that the line of code continues on to the next line.

Or, change it to
.Bookmarks("Text1").Range.InsertBefore TextBox1
.Bookmarks("Text2").Range.InsertBefore TextBox2
No spaces and no underscores, all on the same line.

Good luck!
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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