First time here, so apologies if this is in the wrong place!
I've hobbled together this VB6.5 macro in Word 2003 that will print multiple pages of the same form that will be bound together in the same book. Each form has space for 3 separate entries of info, and each entry is numbered 1-3. When the form is opened a window pops up and asks the user to enter the book number, then another one opens and asks the user to enter the number of pages in the book. The values are then pasted in multiple locations on the page in the format xxx-yy-zz where xxx is the book number entered, yy is the page number and zz is a hardcoded 01, 02, or 03. This gives each entry in the book a unique tracking number. At the bottom of each page is another bookmark which gives "Page xx of yy".
The question is probably simple, but it's 5pm, my head hurts, and I want to go home....
How do I get the yy (page number) to paste as 2-digits, i.e. as "01" when <10, or as "99" when >10. The book will never have more than 99 pages.
BookNumber1 to BookNumber3 are the 3 locations on the form where the book number goes.
SerialNumber1 to SerialNumber4 are the 4 locations on teh form where the page number goes
NumCopies is the total number of pages.
THANKS!!!
I've hobbled together this VB6.5 macro in Word 2003 that will print multiple pages of the same form that will be bound together in the same book. Each form has space for 3 separate entries of info, and each entry is numbered 1-3. When the form is opened a window pops up and asks the user to enter the book number, then another one opens and asks the user to enter the number of pages in the book. The values are then pasted in multiple locations on the page in the format xxx-yy-zz where xxx is the book number entered, yy is the page number and zz is a hardcoded 01, 02, or 03. This gives each entry in the book a unique tracking number. At the bottom of each page is another bookmark which gives "Page xx of yy".
The question is probably simple, but it's 5pm, my head hurts, and I want to go home....
How do I get the yy (page number) to paste as 2-digits, i.e. as "01" when <10, or as "99" when >10. The book will never have more than 99 pages.
BookNumber1 to BookNumber3 are the 3 locations on the form where the book number goes.
SerialNumber1 to SerialNumber4 are the 4 locations on teh form where the page number goes
NumCopies is the total number of pages.
THANKS!!!
Code:
Public strCode As String
Sub Autoopen()
'This unlocks the document if it is locked at start
If ActiveDocument.ProtectionType <> wdNoProtection Then ActiveDocument.Unprotect "password"
Dim Message1, Title1, Default1, MyValue1
Message1 = "Enter the book number for printing:" ' Set prompt.
Title1 = "Book Number" ' Set title.
Default1 = "000" ' Set default.
' Display message, title, and default value.
MyValue1 = InputBox(Message1, Title1, Default1)
strCode = MyValue1
'Inserts the book number inside the document
ActiveDocument.Bookmarks("BookNumber1").Range.InsertBefore strCode
ActiveDocument.Bookmarks("BookNumber2").Range.InsertBefore strCode
ActiveDocument.Bookmarks("BookNumber3").Range.InsertBefore strCode
Dim Message As String
Dim Title As String
Dim Default As String
Dim NumCopies As Long
Dim Rng1 As Range
Dim Rng2 As Range
Dim Rng3 As Range
Dim Rng4 As Range
' Set prompt.
Message = "Enter the number of pages that you want to print"
' Set title.
Title = "Print"
' Set default.
Default = "1"
' Set first page.
SerialNumber = 1
' Display message, title, and default value.
NumCopies = Val(InputBox(Message, Title, Default))
Set Rng1 = ActiveDocument.Bookmarks("SerialNumber1").Range
Set Rng2 = ActiveDocument.Bookmarks("SerialNumber2").Range
Set Rng3 = ActiveDocument.Bookmarks("SerialNumber3").Range
Set Rng4 = ActiveDocument.Bookmarks("SerialNumber4").Range
Counter = 0
Set Rng5 = ActiveDocument.Bookmarks("NumCopies").Range
While Counter < NumCopies
Rng1.Delete
Rng1.Text = SerialNumber
Rng2.Delete
Rng2.Text = SerialNumber
Rng3.Delete
Rng3.Text = SerialNumber
Rng4.Delete
Rng4.Text = SerialNumber
Rng5.Text = NumCopies
ActiveDocument.PrintOut
SerialNumber = SerialNumber + 1
Counter = Counter + 1
Wend
'Recreate the bookmark ready for the next use.
With ActiveDocument.Bookmarks
.Add Name:="SerialNumber1", Range:=Rng1
.Add Name:="SerialNumber2", Range:=Rng2
.Add Name:="SerialNumber3", Range:=Rng3
.Add Name:="SerialNumber4", Range:=Rng4
.Add Name:="NumCopies", Range:=Rng5
End With
'This locks the document at the end of the macro
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:="password"