HOWTO: Make Word Print Duplex Using OLE AutomationID: Q194306
|
This article demonstrates how to use OLE automation from Visual FoxPro to Microsoft Word for Windows 97 to print a document duplex.
Since the dialog box that sets duplex printing is part of the printer
setup, there is not a direct command that you can issue that causes a
document to print duplex. However, there are three ways that do work
allowing you to print documents duplex.
The printer used in this test is a Hewlett-Packard LaserJet printer, which
supports duplex printing.
oWord=CREATEOBJECT("Word.Application")
WITH oWord
.Visible=.T.
.Documents.Add
.Activewindow.View.ShowFieldCodes=0 && Don't view field codes.
* Insert PRINT field & Hewlett-Packard escape code for duplex, long-
* edge binding.
* It is an ampersand, lower-case L, numeric 1, and upper-case S.
.Selection.Fields.Add(.Selection.Range,-1,"PRINT 27 &l1S")
.Selection.Moveright
.Selection.Insertafter("Page 1")
.Selection.Moveright
odlog=oWord.Dialogs(159) && Insert page break w/ Dialogs collection.
odlog.Execute
.Selection.Insertafter("Page 2")
.Selection.Moveright
.Printout(0) && 0 turns off background printing.
.Application.Quit(0) && Quit, don't save & don't prompt.
ENDWITH
This code does not work if the Word document contains mixed orientation,
that is portrait and landscape sections.
oWord=CREATEOBJECT("Word.Application")
WITH oWord
.Visible=.T.
.Documents.Add
* This code creates a two page document to print.
.Selection.Insertafter("Page 1 - With SendKeys")
.Selection.Moveright
odlog=oWord.Dialogs(159) && Insert page break w/ Dialogs collection.
odlog.Execute
.Selection.Insertafter("Page 2 - With SendKeys")
.Selection.Moveright
* End of document creation.
.Application.Activate
.Wordbasic.Sendkeys("%fp%p%d{enter}{tab}{enter}", -1)
=INKEY(2) && May need to wait couple seconds before quitting.
.Application.Quit(0) && Quit, don't save & don't prompt.
ENDWITH
In the Sendkeys command, the % sign represents using the ALT key to access
Windows menus. The INKEY() command allows Word to process the keystrokes
before Visual FoxPro for Windows processes the Quit. This may need to be
adjusted up, down, or removed depending on the application.
oWord=CREATEOBJECT("Word.Application")
WITH oWord
.Visible=.T.
.Documents.Add
.Application.Activate
.Run("SendKey")
.Application.Quit(0) && Quit, don't save & don't prompt.
ENDWITH
The minimum code for the Word macro to send the keys for duplex printing
follows:
Sub SendKey()
SendKeys "%fp%p%d{enter}{tab}{enter}"
End Sub
NOTE: Please see the NOTE in Method 2 for problems you may encounter using
SendKeys.
For additional information, please see the following articles in the Microsoft Knowledge Base:
Q69939 How to Use Percent, Caret, and Plus SendKeys in WinWord
Q135569 WD: PCL Escape Codes to Use with the PRINT FieldFor more information about obtaining Word for Windows 97 Service Release 1 (SR-1), please see the following article in the Microsoft Knowledge Base:
Q172475 OFF97: How to Obtain and Install MS Office 97 SR-1Microsoft Word Visual Basic Help
Additional query words: kbVFp600 kbole kbInterOp kbvfp500a
Keywords :
Version : WINDOWS:5.0a,6.0
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: July 30, 1999