This is a cut and paste article from http://wordribbon.tips.net/T009540_Using_Sequential_Document_Serial_Numbers.html
Credit to original author.
Using Sequential Document Serial Numbers
by Allen Wyatt (last updated November 20, 2010)
If you have a need to create serial numbers in your documents and they are very simple in nature, you can do so using a macro. This approach to serial numbers is great if your serial numbers are sequential (1, 2, 3, etc.) or regular in their incidence (3, 5, 7, etc.).
To begin, you should enter the macro that will control the change of the serial number and the printing of your document. You can use the following macro:
Sub MySerial()
Dim rngSerialLocation As Range
Dim intSerialNum As Integer
Dim strSerialNum As String
Dim docCurrent As Document
Dim intNumCopies As Integer
Dim intCount As Integer
' set ref to current active doc
Set docCurrent = Application.ActiveDocument
' set ref to the bookmarked serial number
Set rngSerialLocation = docCurrent.Bookmarks("Serial").Range
' get the starting number
intSerialNum = Val(rngSerialLocation.Text)
' get the number of copies required
intNumCopies = Val(InputBox$("How many Copies?", _
"Print Serialized", "1"))
For intCount = 1 To intNumCopies
' print the document
docCurrent.PrintOut Range:=wdPrintAllDocument
' increment the serial number
intSerialNum = intSerialNum + 1
' put into formatted version
strSerialNum = Format(intSerialNum, "00000")
' stuff into proper place
rngSerialLocation.Text = strSerialNum
Next intCount
' reset the bookmark, since the updating procedure
' wipes out the old one
docCurrent.Bookmarks.Add Name:="Serial", _
Range:=rngSerialLocation
End Sub
There is only one prerequisite to using the macro: you need to make sure that your document contains a bookmark named Serial. This bookmark should reference the serial number in your document, as you want it to appear in the first printed document. (When you are through running the macro, you can save the document and the serial number will be ready for the next time you want to use it.)
The macro also assumes that your serial number consists primarily of some numeric value that changes with each iteration. You can modify the incrementing of the serial number, as well as its formatting, in the For...Next loop within the macro.
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (9540) applies to MS Word versions: 2007 | 2010
Credit to original author.
Comments