Sequential Numbering

C

Code Numpty

I have the following macro which inserts sequential serial numbering in a
bookmark field and prints out automatically.
---------------------------------------------------------
Sub SEQserialnumber()
Dim Counter As Long
Dim NumCopies As Long
Dim Rng1 As Range
Dim SerialNumber As String
Dim Fld As Field

NumCopies = Val(InputBox("Enter the number of copies that you want to
print." _
& vbCr + vbCr & "Get it right you can't stop it!", "Print", "1"))

SerialNumber = Val(InputBox("Enter the starting SERIAL number", "Serial
Number", _
"0000001"))

ActiveDocument.Fields.Update

Set Rng1 = ActiveDocument.Bookmarks("SerialNumber").Range
Counter = 0

While Counter < NumCopies
Rng1.Delete
Rng1.Text = Format(SerialNumber, "000000#")
With ActiveDocument.Bookmarks
..Add Name:="SerialNumber", Range:=Rng1
End With
'For Each Fld In ActiveDocument.Fields
'If Fld.Type = wdFieldRef Then Fld.Update
'Next
ActiveDocument.PrintOut
SerialNumber = SerialNumber + 1
Counter = Counter + 1
Wend
ActiveDocument.Close SaveChanges:=False
End Sub
---------------------------------------------------------

I now need to add an additional bookmark for a Certificate Number to work in
the same way, starting from the user entered number and increasing by 1 for
every copy.

Is it possible to have the 2 in the same file? If so I'd be grateful for
some help with this.
 
G

Graham Mayor

You can have as many bookmarks and numbering sequences as you like. It might
however be better to store the numbers in an ini file to avoid the
requirement to key in the sequence start numbers. See
http://www.gmayor.com/automatic_numbering_documents.htm

However to modify your code (and give the user the option to cancel)

Sub SEQserialnumber()
Dim Counter As Long
Dim NumCopies As String
Dim Rng1 As Range
Dim Rng2 As Range
Dim SerialNumber As String
Dim CertNumber As String
Dim Fld As Field

NumCopies = InputBox("Enter the number of copies that you want to print." _
& vbCr + vbCr & "Get it right you can't stop it!", "Print", "1")

If NumCopies = "" Then GoTo Cancelled:

SerialNumber = InputBox("Enter the starting SERIAL number", _
"Serial Number", "1")
If SerialNumber = "" Then GoTo Cancelled:

CertNumber = Val(InputBox("Enter the starting CERTIFICATE number", _
"Certificate Number", "1"))
If CertNumber = "" Then GoTo Cancelled:

ActiveDocument.Fields.Update

Set Rng1 = ActiveDocument.Bookmarks("SerialNumber").Range
Set Rng2 = ActiveDocument.Bookmarks("CertNumber").Range

Counter = 0

While Counter < NumCopies
Rng1.Text = format(SerialNumber, "000000#")
With ActiveDocument.Bookmarks
.Add name:="SerialNumber", Range:=Rng1
End With
Rng2.Text = format(CertNumber, "000000#")
With ActiveDocument.Bookmarks
.Add name:="CertNumber", Range:=Rng2
End With
ActiveDocument.PrintOut
SerialNumber = SerialNumber + 1
CertNumber = CertNumber + 1
Counter = Counter + 1
Wend
ActiveDocument.Close wdDoNotSaveChanges
Exit Sub
Cancelled:
MsgBox "User cancelled", vbInformation, "Cancelled"
End Sub
 

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