How do i insert sequential numbers into a Word document template?

G

Guest

I have a document template in Word which I use as an Invoice and I want the
numbers to automatically update as I use it. Is this possible?
 
G

Guest

I have looked at that but am a novice and don't really understand it -
although I have tried to do it!!
Jo
 
J

Jay Freedman

Here are instructions for putting the macro into your template:
http://www.gmayor.com/installing_macro.htm

All you need to do is copy the macro from the NumberDocs web page and paste
it into the macro editor the way the installing_macro article describes. In
the body of the template, insert the bookmark named Order where the number
should appear. Then save the template.
 
G

Guest

Thanks a lot - managed it in the end!!

Jo

Jay Freedman said:
Here are instructions for putting the macro into your template:
http://www.gmayor.com/installing_macro.htm

All you need to do is copy the macro from the NumberDocs web page and paste
it into the macro editor the way the installing_macro article describes. In
the body of the template, insert the bookmark named Order where the number
should appear. Then save the template.
 
G

Guest

Jay Freedman said:
Here are instructions for putting the macro into your template:
http://www.gmayor.com/installing_macro.htm

All you need to do is copy the macro from the NumberDocs web page and paste
it into the macro editor the way the installing_macro article describes. In
the body of the template, insert the bookmark named Order where the number
should appear. Then save the template.
 
G

Guest

I'm confused! I followed the instructions and copied the NumberDocs macro
into my normal.dot / newmacros template. I inserted the bookmark "order" in
the space after Invoice# and saved the Invoice template. But when I open a
new document from the template I get a run-time error that says Method
'PrivateProfileString' of object 'System' failed. The run-time error is
numbered '-2147467259 (80004005)'. Can you help me figure out what I did
wrong??? I read all the help files about ERR object properties and tried ON
ERROR RESUME NEXT statement. That produced a document with invoice number
001001, and each successive iteration added another 001 to the string. ie.
001001001 etc.
Thank you in advance...
ddiamondave
 
G

Graham Mayor

You didn't follow the instructions, which say that you should put the
autonew macro not in normal.dot, but in the document template ie in your
invoice template.

The macro itself is fairly straightforward and shouldn't cause any problems.
You'll find an essentially similar version at
http://www.gmayor.com/automatic_numbering_documents.htm though this one
doesn't use a bookmark to locate the number, but places it in the header.

Both macros work correctly if you follow the instructions provided.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Guest

Please explain. The following is instruction 2 pasted from your idiots guide:

In the field directly beneath the macro names list box, pick which template
or document you wish the macro to be saved in. If you select 'All active
templates and documents' - as here - the macro will be saved in the normal
template.

instruction 3 is 'create'
instruction 4 thru 6 cut and paste the macro text... and instruction 7 saves
it

I've been in my invoice template throughout this proceedure. What am I
missing???
 
G

Graham Mayor

What you are missing is that Word, by default, always saves macros in
normal.dot. You have to tell it to save them in your template (even if that
template is open for editing). This is illustrated at instruction 2 that you
have quoted. There the macro is saved in normal.dot. You need it to be in
your invoice document template. Cut and paste it to the correct location.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Guest

It's still not working. I copied the AUTONEW macro to the newmacros module in
my invoice template, saved the template as directed. When I open a new doc
from the template I get the same run-time error. My operating system is
VISTA, could that cause the failure? I've search for the file "Settings.txt"
and can't find it.
 
G

Graham Mayor

The error message concerns the file save location. I don't have Vista so I
cannot test whether Vista will let you write to the root of the C drive,
however with a small change the macro will change to a different folder - in
the following example the Word Startup Folder. So try the following
variation
The line
SettingsFile="C:\Path\Settings.txt"
is an alternative for the line that follows should you wish to nominate a
specific folder that you have write access to, to store the settings.txt
file.


Sub AutoNew()
Dim SettingsFile As String
'SettingsFile="C:\Path\Settings.txt"
SettingsFile = Options.DefaultFilePath(wdStartupPath) & "\Settings.txt"
Order = System.PrivateProfileString(SettingsFile, _
"MacroSettings", "Order")

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

System.PrivateProfileString(SettingsFile, "MacroSettings", _
"Order") = Order

ActiveDocument.Bookmarks("Order").Range.InsertBefore Format(Order, "00#")
ActiveDocument.SaveAs FileName:="path" & Format(Order, "00#")

End Sub



--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
Joined
Dec 30, 2018
Messages
1
Reaction score
0
How do I set a specific number to start at? I'm using Windows 10 and can't seem to find the settings.txt file location.
 

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