askrates
06-08-2014, 11:47 PM
Hi Everyone,
I hope some kind soul can help. I am working on a macro in word to do two simple things:
1) Create an increasing serial number (at a bookmarked location) on a word document that increases by 1 for every copy printed
2) Prints the serial number as a barcode (at another bookmarked location). The number has to be deleted before moving on to the next page, or the paper will fill up with barcodes!
The first part works, but the second part doesn't. I cannot get it to print anything.
Any advice welcome
Public Sub CoverSheetNumber()
Dim Message As String, Title As String, Default As String, NumCopies As Long
Dim Rng1 As Range
Dim StrCode As String
' Set prompt.
Message = "Enter number of sheets"
' Set title.
Title = "Print"
' Set default.
Default = "1"
' Display message, title, and default value.
NumCopies = Val(InputBox(Message, Title, Default))
SerialNumber = 1
If SerialNumber = "" Then
SerialNumber = 1
End If
'Set ranges (bookmarked places in document)
Set Rng1 = ActiveDocument.Bookmarks("B1").Range
Counter = 0
Set Rng2 = ActiveDocument.Bookmarks("B2").Range
Counter = 0
'Insert values and print
While Counter < NumCopies
Rng1.Delete
Rng2.Delete
Rng1.Text = SerialNumber
Rng2.Text = "*2014-" & SerialNumber & "*"
Rng2.Collapse wdCollapseStart
Rng2.Font.Name = "3 of 9 Barcode"
Rng2.Font.Size = 28
ActiveDocument.PrintOut
SerialNumber = SerialNumber + 1
Counter = Counter + 1
Wend
'Save the bookmark ready for the next use.
With ActiveDocument.Bookmarks
.Add Name:="B1", Range:=Rng1
.Add Name:="B2", Range:=Rng2
End With
End Sub
I hope some kind soul can help. I am working on a macro in word to do two simple things:
1) Create an increasing serial number (at a bookmarked location) on a word document that increases by 1 for every copy printed
2) Prints the serial number as a barcode (at another bookmarked location). The number has to be deleted before moving on to the next page, or the paper will fill up with barcodes!
The first part works, but the second part doesn't. I cannot get it to print anything.
Any advice welcome
Public Sub CoverSheetNumber()
Dim Message As String, Title As String, Default As String, NumCopies As Long
Dim Rng1 As Range
Dim StrCode As String
' Set prompt.
Message = "Enter number of sheets"
' Set title.
Title = "Print"
' Set default.
Default = "1"
' Display message, title, and default value.
NumCopies = Val(InputBox(Message, Title, Default))
SerialNumber = 1
If SerialNumber = "" Then
SerialNumber = 1
End If
'Set ranges (bookmarked places in document)
Set Rng1 = ActiveDocument.Bookmarks("B1").Range
Counter = 0
Set Rng2 = ActiveDocument.Bookmarks("B2").Range
Counter = 0
'Insert values and print
While Counter < NumCopies
Rng1.Delete
Rng2.Delete
Rng1.Text = SerialNumber
Rng2.Text = "*2014-" & SerialNumber & "*"
Rng2.Collapse wdCollapseStart
Rng2.Font.Name = "3 of 9 Barcode"
Rng2.Font.Size = 28
ActiveDocument.PrintOut
SerialNumber = SerialNumber + 1
Counter = Counter + 1
Wend
'Save the bookmark ready for the next use.
With ActiveDocument.Bookmarks
.Add Name:="B1", Range:=Rng1
.Add Name:="B2", Range:=Rng2
End With
End Sub