need help with numbering in template

G

Guest

Using word 2002. wish to set document to have a number which would change
each time a new document was opened. Example go file/new and open the custom
template letter, the letter has an area that says 2007-01. the next time the
template is opened this number would be 2007-02 and so on. Then next year
you start all over with 2008-01. Is this possible and if so how do you do
it.... thanks
 
G

Graham Mayor

See http://word.mvps.org/FAQs/MacrosVBA/NumberDocs.htm or using the registry
(for a single user system)
http://www.gmayor.com/automatic_numbering_documents.htm

Both methods can be adapted to include the year - e.g. in Doug's macro
(first link) change the last two lines to

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


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

My web site www.gmayor.com

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

Guest

I managed to get the macro in the template.
When I open a new document it keeps opening at 003
What have I done wrong... I used the auto new macro: here is the code:
Sub invoicenumber()
'
' invoicenumber Macro
' Macro created 1/28/2007 by me
'

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

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

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

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

End Sub
 
G

Graham Mayor

While testing you have written entries to settings.txt. Open settings.txt
and delete the line order=002 and start again.
The number here is always the last number used.
It might reduce confusion if you change all incidences of 'Order' to
'Invoice' - including the bookmark!

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

My web site www.gmayor.com

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

Graham Mayor

Incidentally "path" in the line
ActiveDocument.SaveAs FileName:="path" & Format(Order, "00#")
represents the actual path to the folder where the document will be saved.

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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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