Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2008

Tip: Looking for answers? Try searching our database.

Select a printer for selected pages

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
BruceM - 06 Feb 2008 20:04 GMT
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.
Doug Robbins - Word MVP - 13 Feb 2008 00:18 GMT
I think that you will find what you need in the article "Changing the
selected (current) printer in Word without changing the system default
printer" at:

http://www.word.mvps.org/FAQs/MacrosVBA/ChangeCurPrinter.htm

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

>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:
[quoted text clipped - 40 lines]
> to hard code a printer name or some other such information it's not a
> problem.
BruceM - 13 Feb 2008 12:20 GMT
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.

>I think that you will find what you need in the article "Changing the
>selected (current) printer in Word without changing the system default
[quoted text clipped - 46 lines]
>> to hard code a printer name or some other such information it's not a
>> problem.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.