B
BruceM
I have some code in an add-in that causes a limited selection of pages to
print from a larger document. A portion of the code goes like this:
Dim p1 As Long ' Start page
Dim p2 As Long ' End page
Dim m1 As Long ' Start page of second section, if any
Dim m2 As Long ' End page of second section, if any
If ActiveDocument.Bookmarks.Exists("ChoosePage") Then
ActiveDocument.PrintOut Range:=wdPrintFromTo, From:=strBkm, To:=strBkm
Else
ActiveDocument.PrintOut Range:=wdPrintFromTo, From:=CStr(p1),
To:=CStr(p2)
End If
If ActiveDocument.Bookmarks.Exists("MoreStart") Then
ActiveDocument.PrintOut Range:=wdPrintFromTo, From:=CStr(m1),
To:=CStr(m2)
End If
The variable p1 is assigned a value thus:
p1 = ActiveDocument.Bookmarks("DocStart").Range _
.Information(wdActiveEndAdjustedPageNumber)
p2, m1, and m2 are assigned similarly.
strBkm comes from a user form that appears if the document contains a
bookmark named "ChoosePage". I mention this to fill in the details so that
my posting makes sense. The code works as intended, but I would prefer that
the user be given the option to select a printer, because this code involves
color printing of a watermark. As it stands the default printer is used.
I found out how to call the Print dialog box:
Dim dlgPgSetup As Dialog
Set dlgPgSetup = Dialogs(wdDialogFilePageSetup)
However, selecting a printer and clicking OK causes the entire document
(often 30 or more pages) to print, rather than the one or two pages that are
generally required. What I would like to do is print the defined ranges (p1
to p2, etc.) on the selected printer.
This printing will take place at no more than two locations, so if I have to
hard code a printer name or some other such information it's not a problem.
print from a larger document. A portion of the code goes like this:
Dim p1 As Long ' Start page
Dim p2 As Long ' End page
Dim m1 As Long ' Start page of second section, if any
Dim m2 As Long ' End page of second section, if any
If ActiveDocument.Bookmarks.Exists("ChoosePage") Then
ActiveDocument.PrintOut Range:=wdPrintFromTo, From:=strBkm, To:=strBkm
Else
ActiveDocument.PrintOut Range:=wdPrintFromTo, From:=CStr(p1),
To:=CStr(p2)
End If
If ActiveDocument.Bookmarks.Exists("MoreStart") Then
ActiveDocument.PrintOut Range:=wdPrintFromTo, From:=CStr(m1),
To:=CStr(m2)
End If
The variable p1 is assigned a value thus:
p1 = ActiveDocument.Bookmarks("DocStart").Range _
.Information(wdActiveEndAdjustedPageNumber)
p2, m1, and m2 are assigned similarly.
strBkm comes from a user form that appears if the document contains a
bookmark named "ChoosePage". I mention this to fill in the details so that
my posting makes sense. The code works as intended, but I would prefer that
the user be given the option to select a printer, because this code involves
color printing of a watermark. As it stands the default printer is used.
I found out how to call the Print dialog box:
Dim dlgPgSetup As Dialog
Set dlgPgSetup = Dialogs(wdDialogFilePageSetup)
However, selecting a printer and clicking OK causes the entire document
(often 30 or more pages) to print, rather than the one or two pages that are
generally required. What I would like to do is print the defined ranges (p1
to p2, etc.) on the selected printer.
This printing will take place at no more than two locations, so if I have to
hard code a printer name or some other such information it's not a problem.