How To Use Code to Print a Word Document in a General Field

Last reviewed: August 13, 1997
Article ID: Q153675
3.00 3.00b WINDOWS kbinterop kbhowto kbcode kbwebcontent

The information in this article applies to:

  • Microsoft Visual FoxPro for Windows, versions 3.0, 3.0b

SUMMARY

If a general field contains an embedded or linked Word document, you can

 print the Word document by using code and OLE automation.

MORE INFORMATION

For more information about the behavior of embedded Word documents, please see the following articles in the Microsoft Knowledge Base:

   ARTICLE-ID: Q105714
   TITLE     : Document Object Margins Default to Zero Inches

   ARTICLE-ID: Q121049
   TITLE     : Wrong Page Size for Word Document Object Opened to Edit

IMPORTANT: If you are using the APPEND GENERAL command, or Insert Object from the Edit menu in the general field to create a new Word document, the document may not print correctly if you do not follow the guidelines published in Microsoft Knowledge Base article Q105714 (see above).

Code Sample

The following code demonstrates how to print the document.

CREATE TABLE myword (wordfld G) APPEND BLANK APPEND GENERAL wordfld CLASS "Word.Document" ** The above lines are for demonstration only ** Normally the table will already exist and contain the document

frmDummy = CREATEOBJECT("Form") frmDummy.ADDOBJECT("objWordDoc","OleBoundControl") frmDummy.objWordDoc.ControlSource = "wordfld" frmDummy.objWordDoc.DoVerb(1) &&starts an instance of Word objWordInst = GETOBJECT("","Word.Basic") &&create a reference to Word ** set paper size - see Q121049 referenced above objWordInst.FilePageSetup(,,"1","1",,"1","1","8.5 in","11 in") objWordInst.Insert("Brown Shoes Don't Make It") objWordInst.AppHide objWordInst.FilePrint WAIT WINDOW "Printing document" TIMEOUT 5 objWordInst.AppClose RELEASE objWordInst


Additional reference words: 3.00 3.00b VFoxWin OLE automation winword
KBCategory: kbinterop kbhowto kbcode kbwebcontent
KBSubcategory: FxinteropWinword
Keywords : FxinteropWinword kbcode kbhowto kbinterop kbwebcontent
Version : 3.00 3.00b
Platform : WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 13, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.