Automatic numbering Problem

S

stuck4once

Hi there,

I have got a macro attached to a template so that whenever the template is
opened it automatically opens and saves under a new sequentual number but,
the document also saves as a template and when I go in to the new saved
document it runs the macro again.

The macro is:

Sub AutoOpen()


Order = System.PrivateProfileString("C:\Documents and Settings\acollin\My
Documents\Order Folder\Settings.Txt", "MacroSettings", "Order")

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

System.PrivateProfileString("C:\Documents and Settings\acollin\My
Documents\Order Folder\Settings.Txt", "MacroSettings", "Order") = Order
ActiveDocument.Bookmarks("order").Range.InsertBefore Format(Order, "#")
ActiveDocument.SaveAs FileName:="C:\Documents and Settings\acollin\My
Documents\Order Folder\Order Number -" & Format(Order, " #")

End Sub

How can I stop the document that it create from being a template? Hopefully
this will then stop the macro from running when opening.

Any help on this will be greatly appreciated.

many thanks
 
R

Russ

Make sure that you are not opening a .dot file directly, otherwise you will
be asked to save changes, if changed while open.
I don't see anything in the code below that is directly altering a .dot
file.
See this website for tips on how to use templates.
<http://www.shaunakelly.com/word/templaterelations/index.html>

Also, templates are not the same as Documents with formfields.
I've got a suspicion that you're talking about on-line forms which should be
set up and saved as templates. Then a new document based on the template is
opened and filled out. You don't open the template or .dot file.
 
D

David Sisson

Russ is right.

How do you get a new Document started? Do you File --> New, or File -->
Open. If it's the latter, then that's your problem.

File --> New creates a document BASED ON the template, but the autorun code
doesn't move with it, so when you open the document later on, there shouldn't
be a new document number generated.
 

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