Auto run macro in template

C

Cottage6

I have a template that includes code to auto number the document created from
the template, and that works fine. I can't get the code to run automatically
when the document is created. I've tried AutoNew, AutoExec, AutoOpen. What
am I doing wrong? Word 2002. Thanks for the help!
 
C

Charles Kenyon

You want AutoNew to run when the document is created. What are your macro
security settings? Where is your template stored?
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide


--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
C

Cottage6

Hi Charles,
Thanks for the response; actually AutoNew is working just fine for me now.
I do have another question maybe you could help with. I've repeated the code
4 times because there are 4 separate certificates that need numbers.
However, now I'm told not all 4 certificates may be used, so they want to
know if there's a way to specify the number of certificates they want
numbered. Maybe use an input box? But I'm very unsure how to do this. I've
included the code I'm using below.

Sub AutoNew()

Order = System.PrivateProfileString("C:\Settings3.Txt", _
"MacroSettings", "Order")

If Order = "" Then
Order = 1
Else
Order = Order + 1
End If

System.PrivateProfileString("C:\Settings3.txt", "MacroSettings", _
"Order") = Order

ActiveDocument.Bookmarks("Order").Range.InsertBefore Format(Order, "0000#")
'***********************************************************************
Order2 = System.PrivateProfileString("C:\Settings3.Txt", _
"MacroSettings", "Order")

If Order2 = "" Then
Order2 = 1
Else
Order2 = Order2 + 1
End If

System.PrivateProfileString("C:\Settings3.txt", "MacroSettings", _
"Order2") = Order2

ActiveDocument.Bookmarks("Order2").Range.InsertBefore Format(Order2, "0000#")

'********************************************************************************
Order3 = System.PrivateProfileString("C:\Settings3.Txt", _
"MacroSettings", "Order")

If Order3 = "" Then
Order3 = 1
Else
Order3 = Order2 + 1
End If

System.PrivateProfileString("C:\Settings3.txt", "MacroSettings", _
"Order3") = Order3

ActiveDocument.Bookmarks("Order3").Range.InsertBefore Format(Order3, "0000#")

'***********************************************************************************
Order4 = System.PrivateProfileString("C:\Settings3.Txt", _
"MacroSettings", "Order")

If Order4 = "" Then
Order4 = 1
Else
Order4 = Order3 + 1
End If

System.PrivateProfileString("C:\Settings3.txt", "MacroSettings", _
"Order4") = Order4

ActiveDocument.Bookmarks("Order4").Range.InsertBefore Format(Order4, "0000#")
ActiveDocument.SaveAs FileName:="Meal Tickets" & Format(Order4, "0000#")

System.PrivateProfileString("C:\Settings3.txt", "MacroSettings", _
"Order") = Order4
End Sub
 
C

Charles Kenyon

I would use an input box or a userform.

However, I'm a novice and not up on privateprofile strings and so am not the
one to answer this question. I would suggest posting a separate question on
it (with an appropriate subject line).
You may also want to look at
http://word.mvps.org/FAQs/MacrosVBA/NumberDocs.htm if you haven't already.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide


--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
J

Jezebel

I do have another question maybe you could help with. I've repeated the
code
4 times because there are 4 separate certificates that need numbers.
However, now I'm told not all 4 certificates may be used, so they want to
know if there's a way to specify the number of certificates they want
numbered. Maybe use an input box? But I'm very unsure how to do this.
I've
included the code I'm using below.

Before you put any more effort into solving the problem, invest some time in
*defining* the problem. "Now I'm told..." is no basis on which to write
code. Write down your understanding of what "they" want, and get "them" to
agree to it. Otherwise you will end up with a great solution to the wrong
problem, or vice versa.
 

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