Sequential number generator for raffle tickets

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can I make a sequential number generator from word that will print numbers
starting at any number I choose (ex: 100500) that will print each number on a
seperate ticket?

Thanks
 
The following is a modification of the code in the article "Sequentially
numbering multiple copies of single document using a macro" at:

http://www.word.mvps.org/FAQs/MacrosVBA/NumberCopiesOf1Doc.htm

that will let you specify the starting number:

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"
' Set title.
Title = "Print"
' Set default.
Default = "1"

' Display message, title, and default value.
NumCopies = Val(InputBox(Message, Title, Default))
SerialNumber = System.PrivateProfileString("C:\Settings.Txt", _
"MacroSettings", "SerialNumber")

If SerialNumber = "" Then
SerialNumber = InputBox("Enter the starting number", "Set Starting
Number", "1")
End If

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

'Save the next number back to the Settings.txt file ready for the next use.
System.PrivateProfileString("C:\Settings.txt", "MacroSettings", _
"SerialNumber") = SerialNumber

'Recreate the bookmark ready for the next use.
With ActiveDocument.Bookmarks
.Add Name:="SerialNumber", Range:=Rng1
End With

ActiveDocument.Save

You may however want to consider whether it might not be better to be using
mailmerge for this where you use a column of numbers in an Excel spreadsheet
as the datasource.
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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

Back
Top