Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2006

Tip: Looking for answers? Try searching our database.

Auto run macro in template

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Cottage6 - 25 Jan 2006 19:11 GMT
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!
Charles Kenyon - 25 Jan 2006 20:16 GMT
You want AutoNew to run when the document is created. What are your macro
security settings? Where is your template stored?
Signature

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

See also the MVP FAQ: http://word.mvps.org/FAQs/ which is awesome!
--------- --------- --------- --------- --------- ---------
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.

>I have a template that includes code to auto number the document created
>from
[quoted text clipped - 3 lines]
> What
> am I doing wrong?  Word 2002.  Thanks for the help!
Cottage6 - 26 Jan 2006 00:48 GMT
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

> You want AutoNew to run when the document is created. What are your macro
> security settings? Where is your template stored?
[quoted text clipped - 5 lines]
> > What
> > am I doing wrong?  Word 2002.  Thanks for the help!
Charles Kenyon - 26 Jan 2006 01:08 GMT
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.
Signature

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

See also the MVP FAQ: http://word.mvps.org/FAQs/ which is awesome!
--------- --------- --------- --------- --------- ---------
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.

> Hi Charles,
> Thanks for the response; actually AutoNew is working just fine for me now.
[quoted text clipped - 85 lines]
>> > What
>> > am I doing wrong?  Word 2002.  Thanks for the help!
Jezebel - 26 Jan 2006 01:14 GMT
> I do have another question maybe you could help with.  I've repeated the
> code
[quoted text clipped - 4 lines]
> 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.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.