Jump to content
Macro Express Forums

Changing Printer


polishmafia
 Share

Recommended Posts

I am looking for a way to change the destination print of a Word document.

 

Basically I am trying to do this;

-Open the word document and print a paper copy to the default Windows printer.

 

-Wait for the print to complete, then print again to PDF writer - without changing the default printer within Windows.

 

I have tried opening the print dialog box, and using tabs, arrow keys, etc to select the PDF writer, but there is a slight problem.

 

Multiple people in multiple locations will be using this macro, and everyone does not have the same amount of printers listed.

 

Any ideas on how this can be done?

 

Thanks in advance!

Link to comment
Share on other sites

Hi, I can't think of an easy solution, so here's a tricky one, which may or may not work..... Firstly the usual caveat - do not alter any registry entries unless you really know what you're doing, and even then take a back up first!

 

How about setting the default device in the registry to what you want before entering the print dialog?

 

I just had a quick look in my registry :ph34r: and this might be it....

 

HKEY_CURRENT_USER\SOFTWARE\MICROSOFT\WINDOWS NT\CURRENTVERSION\WINDOWS, Device

 

read what it is

store it

set it to what you want

print dialog

set it back to what it was.

 

You will probably have to re-enter the printer dialog each time after setting it for it to be selected.

 

I haven't tried this and I don't know that it will work, but it's worth a try if there's no other solution - good luck.

 

Pete.

Link to comment
Share on other sites

The relevant Word VBA code is a simple one-liner!

objWord.Dialogs(PRINT_DIALOG).Display

 

This allows the user to change printers without affecting the default printer setting.

 

If you refer back to one of Joe's several messages about constructing dynamic VB Script modules, you should be able to incorporate the above line into a simple vbs script.

Link to comment
Share on other sites

  • 3 weeks later...

I read your question and realised I was looking for the exact same thing (I think). I have since worked it out. The actual code only ends up being 5 lines, but I have added comments so you can see what each bit does - works like a charm!

 

'----------------------------------------------------------------

'STEP 1

'DETERMINE THE ACTUAL NAME OF CURRENT DEFAULT PRINTER

'Retrieve name of current default printer and

'Display printer name in a message box

'-----------------------------------------------------------------

 

'This constant is used to hold the title of the message box

Const Caption As String = "The Default Printer Name Is"

 

'This variable is used to hold the name of the active printer

Dim DefaultPrinterName As String

 

'Assign the active printer to the variable

DefaultPrinterName = Application.ActivePrinter

 

'Display the message box

MsgBox DefaultPrinterName, vbInformation, Caption

 

'THE RESULT IS A MESSAGE BOX DISPLAYING THE ACTUAL PRINTER NAME

 

'-----------------------------------------------------------------

'STEP 2

'PRINT TO PRINTER OTHER THAN CURRENT DEFAULT

'-----------------------------------------------------------------

'Retrieve name of current default printer and hold as variable

'-----------------------------------------------------------------

'This variable is used to hold the name of the active printer

Dim DefaultPrinterName As String

 

'Assign the active printer to the variable

DefaultPrinterName = Application.ActivePrinter

 

'-----------------------------------------------------------------

'Print to other printer, eg Adobe PDF (becomes default printer)

'-----------------------------------------------------------------

ActivePrinter = "Adobe PDF"

Application.PrintOut Range:=wdPrintAllDocument, _

Item:=wdPrintDocumentContent, Copies:=1

 

'-----------------------------------------------------------------

'Change default printer back to original default printer

'-----------------------------------------------------------------

Application.ActivePrinter = DefaultPrinterName

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...