Select a printer for selected pages

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.
 
B

BruceM

Thanks for the reply. I hadn't heard anything for two days after I posted
this, so I started a new thread with a streamlined explanation of the
problem. One of the suggestions I received was similar to the one in the
link you provided, but in the end I followed a suggestion by Graham Mayor to
use the method here to list available printers:
http://word.mvps.org/FAQs/MacrosVBA/AvailablePrinters.htm

Then I used another routine to save the current default printer as a string
variable, select and print to an available printer with "Color Laser" in the
name, and restore the default printer. The advantage is that I don't need
to use the printer name in code. The caveat is that I need to be sure the
printer name includes the words "Color Laser". If the default printer does
not include "Color Laser" but another available printer does, the user is
presented with a OK/Cancel message box stating to which printer the document
selection will be sent.

I waited two days before starting another thread in which I explained that I
was restating the question from an earlier thread, but I am sorry that the
original posting led you to reply to a question that had been answered
elsewhere. However, the two replies that pointed to code on the word.mvps
web site has reminded me that I would do well to start there when I
investigate future questions, so your reply is of definite if indirect
value.

Thanks again for your reply.
 

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

Top