Sequentially Numbering Printed Output

J

Jem

Hi

I have an application form with a tear off part at the bottom. I would like
to print a number on the top part of the form with the same number repeated
on the tear off bottom part of the form.

I would like these numbers to increment by 1 each time a copy of the
document is printed out therefore uniquely identifying each page that is
printed out.

I would like the last number to be remembered so that the next time I come
around to printing the forms the program picks up where it left off in the
number sequence the last time the program was run.

Is this possible in MS Word?

Hope that makes it resonably clear. Many thanks for any help in advance.

Jem
 
G

Greg Maxey

You will need a couple of bookmarks where your numbers need to appear.

Let's call then FirstCopyNum and SecondCopyNum.

Run this macro:

Sub PrintNumberedCopies()
Dim NumCopies As String
Dim StartNum As String
Dim Counter As Long
Dim oRng1 As Range
Dim oRng2 As Range

With ActiveDocument
If .Saved = False Then
If MsgBox("Do you want to save any changes before" & _
" printing?", vbYesNoCancel, "Save document?") _
= vbYes Then
.Save
End If
End If
On Error GoTo Handler
StartNum = ActiveDocument.Variables("StartNum").Value
NumCopies = Val(InputBox("Enter the number of copies that" & _
" you want to print", "Copies", 1))
Counter = 0
Set oRng1 = .Bookmarks("FirstCopyNum").Range
Set oRng2 = .Bookmarks("SecondCopyNum").Range

If MsgBox("Are you sure that you want to print " _
& NumCopies & " numbered " & " copies of this document", _
vbYesNoCancel, "On your mark, get set ...?") = vbYes Then
While Counter < NumCopies
oRng1.Text = StartNum
.Bookmarks.Add "FirstCopyNum", oRng1
oRng2.Text = StartNum
.Bookmarks.Add "SecondCopyNum", oRng2
.PrintOut
StartNum = StartNum + 1
Counter = Counter + 1
Wend
End If
.Variables("StartNum").Value = StartNum
oRng1.Text = StartNum
.Bookmarks.Add "FirstCopyNum", oRng1
oRng2.Text = StartNum
.Bookmarks.Add "SecondCopyNum", oRng2
Exit Sub
End With
Handler:
ActiveDocument.Variables("StartNum").Value = Val(InputBox("Enter the
starting number.", _
"Starting Number", 1))
Resume
End Sub
Sub ResetStartNum()
ActiveDocument.Variables("StartNum").Delete
End Sub
 
J

Jem

Hi Greg

BRILLIANT !!!!

Thanks a load, this works a treat. All I can say is thank goodness that I
asked the question on the group and that you replied. I would never in a
hundred years have worked this one out for myself. I did try but was waaaay
off the mark, I never even thought of writing a macro.

Cheers

Jem
 

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