B
Bruce
I don't know if I should be asking this here or in
numbering. I'll start here. I have a one page document
(for a log book) that needs to be sequentially numbered.
I have applied the code at
http://word.mvps.org/FAQs/MacrosVBA/NumberCopiesOf1Doc.htm,
which works as intended. However, I would also like to
include the total number of pages (Page X of Y). For easy
reference, here is the VBA code (SerialNumber is the name
of a bookmark in the document footer):
Dim Message As String, Title As String, Default As String,
_ NumCopies As Long
Dim Rng1 As Range
' Set prompt.
Message = "Enter 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 = 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
How can I add the total number of pages based on the entry
in the message box? I can use something like the
following (instead of Rng1.Text = SerialNumber):
Rng1.Text = "Page " & SerialNumber & " of 100", which
works fine as long as I need 100 copies. Is there a way
that the number I typed when the macro started (when the
message box came up) can replace " of 100" in the
expression above?
I am not saving the document, just printing it, so I have
removed the last line of code. Also, in the code
following the remark 'Save the next number back to the
Settings.txt ... I used = 1 rather than = SerialNumber in
order to reset the text file to start over from page 1
each time (several templates will be using this same
code). Is that a good approach to those issues?
I realize I could manipulate this easily enough either by
changing the code or by placing the bookmark SerialNumber
thus: Page (SerialNumber) of 100 in the footer or
something like that, but I am trying to have this system
be self-perpetuating so that it does not require my direct
intervention each time.
numbering. I'll start here. I have a one page document
(for a log book) that needs to be sequentially numbered.
I have applied the code at
http://word.mvps.org/FAQs/MacrosVBA/NumberCopiesOf1Doc.htm,
which works as intended. However, I would also like to
include the total number of pages (Page X of Y). For easy
reference, here is the VBA code (SerialNumber is the name
of a bookmark in the document footer):
Dim Message As String, Title As String, Default As String,
_ NumCopies As Long
Dim Rng1 As Range
' Set prompt.
Message = "Enter 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 = 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
How can I add the total number of pages based on the entry
in the message box? I can use something like the
following (instead of Rng1.Text = SerialNumber):
Rng1.Text = "Page " & SerialNumber & " of 100", which
works fine as long as I need 100 copies. Is there a way
that the number I typed when the macro started (when the
message box came up) can replace " of 100" in the
expression above?
I am not saving the document, just printing it, so I have
removed the last line of code. Also, in the code
following the remark 'Save the next number back to the
Settings.txt ... I used = 1 rather than = SerialNumber in
order to reset the text file to start over from page 1
each time (several templates will be using this same
code). Is that a good approach to those issues?
I realize I could manipulate this easily enough either by
changing the code or by placing the bookmark SerialNumber
thus: Page (SerialNumber) of 100 in the footer or
something like that, but I am trying to have this system
be self-perpetuating so that it does not require my direct
intervention each time.