Friday, May 22, 2015

Sequentially Number Invoices

Creating sequentially numbered documents

Use an Autonew macro to add a sequential number to a document and save it with that number.

In the template from which you create the document, insert a bookmark named Order in the location where you want the sequential number to appear and create an AutoNew macro, as follows:

Sub AutoNew()
Order = System.PrivateProfileString("C:\Settings.Txt", "MacroSettings", "Order")
If Order = "" Then
Order = 1
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 

If you do not need to display the number in the document, but just want to save it with a sequential number, there is no need to create the bookmark in the template and you should then delete the second last line of the code.

Article contributed by Doug Robbins
Word MVP Site

Microsoft Knowledgebase:
Macro to Increment Invoice Number to New Form Document

See all Topics

No comments: