We are trying to produce a printed form which clients will then fill in by
hand.
We would like to be able to print off multiple copies of the form which
would be identical except for a "form number" inserted in two locations in
the page. The form number is a simple numeric, incremented by one between
forms, and will carry on from our current total (i.e. won't start at 1)
One thought was to create a CSV file containing the numbers and then
mail-merge-to-printer this into the main document but I feel there should be
a more 'elegant' solution. e.g. using VBA. which would "remember" where it
is up to, so wouldn't require a new CSV file for each batch we produce.
I have looked through the MS numbering and VBA NGs and my Word books but
cannot find any examples of automating this process, although I am sure it
is a common scenario.
I would be very grateful for any suggestions or URLs to look-up for more
info
Mat
If you insert two bookmarks named CopyNumber1 and CopyNumber2 in the
document where you want the copy numbers to appear and you use the following
macro to print the document, it will ask for number of copies that you want
to make and sequentially number each copy with numbers starting from 1 more
that the number stored in the PrivateProfileString CopyNumber in the file
Settings.Txt that it creates the first time that it is run. To get the
starting number that you want, run it once to create that file, then open
that file and replace the number in it with the last number that you used.
Dim Message, Title, Default, NumCopies
Message = "Enter the number of copies that you want to print" ' Set
prompt.
Title = "Print" ' Set title.
Default = "1" ' Set default.
' Display message, title, and default value.
NumCopies = Val(InputBox(Message, Title, Default))
CopyNumber = System.PrivateProfileString("C:\Settings.Txt", _
"MacroSettings", "CopyNumber")
If CopyNumber = "" Then
CopyNumber = 1
Else
CopyNumber = CopyNumber + 1
End If
Dim rng1 As Range, rng2 As Range
Set rng1 = ActiveDocument.Bookmarks("CopyNumber1").Range
Set rng2 = ActiveDocument.Bookmarks("CopyNumber2").Range
Counter = 0
While Counter < NumCopies
rng1.Delete
rng2.Delete
rng1.Text = CopyNumber
rng2.Text = CopyNumber
ActiveDocument.PrintOut
CopyNumber = CopyNumber + 1
Counter = Counter + 1
Wend
System.PrivateProfileString("C:\Settings.txt", "MacroSettings", _
"CopyNumber") = CopyNumber
With ActiveDocument.Bookmarks
.Add Name:="CopyNumber1", Range:=rng1
.Add Name:="CopyNumber2", Range:=rng2
End With
ActiveDocument.Save
--
Please post any follow-up or new questions to the Newsgroups so that others
may benefit therefrom or contribute thereto.
Hope this helps,
Doug Robbins - Word MVP
Matthew Day <matth...@buckingham.ac.uk> wrote in message
news:OUjMBz22$GA....@cppssbbsa02.microsoft.com...
Great, just the ticket!
One tiny modification - since CopyNumber is incremented at the end of the
While loop, it isn't necessary to increment it in the If/Else statement (as
this leads to a number being skipped between runs).
Thanks again
Matthew
Doug Robbins wrote in message ...
Right you are. The macro was a modification of another one that
sequentially numbered documents and hence did not have the While Wend loop
in it.
Please post any follow-up or new questions to the Newsgroups so that others
may benefit therefrom or contribute thereto.
Hope this helps,
Doug Robbins - Word MVP
Matthew Day <matth...@buckingham.ac.uk> wrote in message
news:uaRjN2C4$GA.244@cppssbbsa04...