Article ID: 194306
Article Last Modified on 1/27/2005
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.
69939 How to use Percent, Caret, and Plus SendKeys in WinWord
135569 PCL escape codes to use with the PRINT field
172475 How to obtain and install MS Office 97 SR-1
Additional query words: kbVFp600 kbole kbInterOp kbvfp500a
Keywords: kbhowto kbcode KB194306