Ask the Expert

Tell Excel or Word to select a printer before printing

This has more to do with the integration between VBA and Lotus Script. How do you tell Excel or Word to select a printer before printing? If this cannot be done, then what about how do I call up a 'Print Preview' instead?

I'll try to give you as much info as I can, since this might be useful in general, as well, to others:

The Print verb is a reserved word in OLE, so it can't be directly called, normally. Several applications (such as WordPro) have created "alternative" methods you can call in its place. These verbs, whichever they are, usually only tell the host application to print (with or without displaying the dialog box).

WordPro:
To Change the Printer Name property:
'This example script sets the current document's printer to the HP LaserJet
	'4L, printing to LPT1:.

	.ActiveDocument.PrintManager.PrintDestination = "LPT1:"
	.ActiveDocument.PrintManager.PrinterName = "HP LaserJet 4L"
	.ActiveDocument.PrintManager.UseDefaultPrinter = True
	.ActiveDocument.PrintManager.UpdatePrinterBins
	.ActiveDocument.PrintManager.GetDefaultPageSize
	.ActiveDocument.PrintManager.UpdatePrinterChanges
	.ActiveDocument.PrintOut([From,][To,][Copies,][nodialog])
Microsoft Word:
. .ActiveDocument.PrintOut(Background, Append, Range, OutputFileName, From, To, Item,Copies, Pages, PageType, PrintToFile, Collate, FileName, ActivePrinterMacGX, ManualDuplexPrint)
	'To select the active printer...
	ActivePrinter = "HP LaserJet IIISi on \printerslaser"
	This example makes a local HP LaserJet 4 printer on LPT1 the active printer. 
	ActivePrinter = "HP LaserJet 4 local on LPT1:"

	'To get a print preview from Word:
	.ActiveDocument.PrintPreview
Microsoft Excel:
As you'd expect, the commands are similar (exactly the same except for the parameters in this case) between Excel and Word:
	ActivePrinter
	.PrintOut(From, To, Copies, Preview, ActivePrinter, PrintToFile, Collate)
	PrintPreview
Lotus 123:
	Much like WordPro, but 123 has a lot more options.  Here's the basics:

	Print:
		Application.PrintOut

	Preview:
		Application.Preview

	Printer Name:
		Application.PrinterName

Hope this helps!


This was first published in April 2002

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: