I use the following macro in Word 2003 to produce sequentially numbered
certificates & have 2 problems with it.


Sub SEQserialnumber()
'
' SEQserialnumber Macro
' Macro created 11/09/2007 by Sharon
'
Dim Counter As Long
Dim Message As String, Title As String, Default As String, NumCopies As
Long
Dim Rng1 As Range

' Set prompt.
Message = "Enter the number of copies that you want to print. Get
it right you can't stop it!"
' Set title.
Title = "Print"
' Set default.
Default = "1"

' Display message, title, and default value.
NumCopies = Val(InputBox(Message, Title, Default))
' Edit from Jay Freedman to enable user to specify serial number
Message = "Enter the starting serial number"
Title = "Serial Number"
SerialNumber = Val(InputBox(Message, Title, Default))

'Next line added to cause Ask field to fire pop-ups
ActiveDocument.Fields.Update

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

While Counter < NumCopies
Rng1.Delete
Rng1.Text = SerialNumber
ActiveDocument.PrintOut
SerialNumber = SerialNumber + 1
Counter = Counter + 1
Wend

'Recreate the bookmark ready for the next use.
With ActiveDocument.Bookmarks
.Add Name:="SerialNumber", Range:=Rng1
End With
'Next line added to update { REF SerialNumber }
'This is more selective than just updating all the fields; in
'particular, the Ask fields (which have .Type = wdFieldAsk) won't be
'updated the second time.
Dim Fld As Field
For Each Fld In ActiveDocument.Fields
If Fld.Type = wdFieldRef Then Fld.Update
Next

ActiveDocument.Close SaveChanges:=False

End Sub

Problem 1: I know find out that serial numbers begin with zeroes e.g.
0000001 to 0000005. If zeroes are entered they do not print and they must do
so to much pre-printed labels.

Problem 2: The 2nd serial number instance is not printing. This is a
mergefield in the document as below.
{ REF SerialNumber \*MERGEFORMAT }

I would be truly grateful for some help with both of these, thanks.

Re: Serial Number Macro Problem with zeroes by Greg

Greg
Mon Jan 07 04:38:33 PST 2008

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 & "Getit 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


--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.


Code Numpty wrote:
> I use the following macro in Word 2003 to produce sequentially
> numbered certificates & have 2 problems with it.
>
>
> Sub SEQserialnumber()
> '
> ' SEQserialnumber Macro
> ' Macro created 11/09/2007 by Sharon
> '
> Dim Counter As Long
> Dim Message As String, Title As String, Default As String,
> NumCopies As Long
> Dim Rng1 As Range
>
> ' Set prompt.
> Message = "Enter the number of copies that you want to print.
> Get it right you can't stop it!"
> ' Set title.
> Title = "Print"
> ' Set default.
> Default = "1"
>
> ' Display message, title, and default value.
> NumCopies = Val(InputBox(Message, Title, Default))
> ' Edit from Jay Freedman to enable user to specify serial number
> Message = "Enter the starting serial number"
> Title = "Serial Number"
> SerialNumber = Val(InputBox(Message, Title, Default))
>
> 'Next line added to cause Ask field to fire pop-ups
> ActiveDocument.Fields.Update
>
> Set Rng1 = ActiveDocument.Bookmarks("SerialNumber").Range
> Counter = 0
>
> While Counter < NumCopies
> Rng1.Delete
> Rng1.Text = SerialNumber
> ActiveDocument.PrintOut
> SerialNumber = SerialNumber + 1
> Counter = Counter + 1
> Wend
>
> 'Recreate the bookmark ready for the next use.
> With ActiveDocument.Bookmarks
> .Add Name:="SerialNumber", Range:=Rng1
> End With
> 'Next line added to update { REF SerialNumber }
> 'This is more selective than just updating all the fields; in
> 'particular, the Ask fields (which have .Type = wdFieldAsk) won't be
> 'updated the second time.
> Dim Fld As Field
> For Each Fld In ActiveDocument.Fields
> If Fld.Type = wdFieldRef Then Fld.Update
> Next
>
> ActiveDocument.Close SaveChanges:=False
>
> End Sub
>
> Problem 1: I know find out that serial numbers begin with zeroes e.g.
> 0000001 to 0000005. If zeroes are entered they do not print and they
> must do so to much pre-printed labels.
>
> Problem 2: The 2nd serial number instance is not printing. This is a
> mergefield in the document as below.
> { REF SerialNumber \*MERGEFORMAT }
>
> I would be truly grateful for some help with both of these, thanks.



Re: Serial Number Macro Problem with zeroes by CodeNumpty

CodeNumpty
Mon Jan 07 04:54:02 PST 2008

Thanks Greg but these 2 lines of code are showing a compile error

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

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

Re: Serial Number Macro Problem with zeroes by David

David
Mon Jan 07 06:16:21 PST 2008

On Jan 7, 4:18=A0am, Code Numpty <CodeNum...@discussions.microsoft.com>
wrote:
> I use the following macro in Word 2003 to produce sequentially numbered
> certificates & have 2 problems with it.
> SerialNumber =3D Val(InputBox(Message, Title, Default))

Your treating the response as a number (integer/long - You don't have
it defined.)

Define it as a string.

Dim SerialNumber as String

Then

SerialNumber =3D InputBox(Message, Title, Default)

If you need to strip the leading zeros later, you can use the Val().

On other note, you can limit the number of copies.

' Display message, title, and default value.
NumCopies =3D Val(InputBox(Message, Title, Default))
If NumCopies > 10 then NumCopies =3D 10.

Limits the total number of copies to ten to prevent a 100 copies due
to input mistake.

Re: Serial Number Macro Problem with zeroes by CodeNumpty

CodeNumpty
Mon Jan 07 06:15:04 PST 2008

Sorry, it was a line break problem. Now works a treat. I just wish I knew why.
Thanks :-)