Printing to a File Using the WordBasic FilePrint Statement

Last reviewed: February 5, 1998
Article ID: Q106250
The information in this article applies to:
  • Microsoft Word for Windows, versions 2.0, 2.0a, 2.0a-CD, 2.0b,

        2.0c, 6.0, 6.0a, 6.0c
    
  • Microsoft Windows operating system versions 3.0 and 3.1

WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

Word 6.0 for Windows

The FilePrint statement in Word 6.0 for Windows includes parameters to allow you to print a document to a file. The FilePrint parameters for printing to a file are listed below.

   .PrintToFile    If 1, sends printer instructions to a file.

   .PrToFileName   If PrintToFile = 1, this parameter specifies the
                   path and filename of the file to print to.

   .AppendPrFile   If PrintToFile = 1, this parameter specifies
                   whether  to overwrite or append to the file if it
                   already exists:

                      0 (zero) Overwrite
                      1        Append

The following command prints the contents of the current document to a file.

   FilePrint .PrToFileName = "C:\Temp\Filename.ext", .Type = 0, \
   .PrintToFile = 1

If you later want to print the contents of the print file, use the following Copy syntax at the MS-DOS prompt:

   copy /b <filename> LPT1:

For more information on the MS-DOS COPY command, refer to pages 389-393 of the "Microsoft MS-DOS User's Guide and Reference" for MS-DOS version 5.0.

Word 2.x for Windows

The FilePrint statement in Word 2.x for Windows does not include a parameter to indicate the print filename (.PrToFileName). To print the contents of the current document to a specific file without being prompted with the filename dialog box, use the SendKeys statement before the FilePrint command. For example:

Sub MAIN
SendKeys "C:\Temp\Filename.ext"        'the filename to print to
SendKeys "{Enter 2}"                   'Send 2 Returns
FilePrint .Type = 0, .PrintToFile = 1
End Sub


KBCategory:
KBSubcategory: kbmacro kbmacroexample
Additional query words: 2.0 2.0a 2.0a-CD 2.0b 2.0c 6.0 6.0a
word6 6.0c
winword winword2
Keywords : kbmacroexample kbmacro kbprint
Version : 2.0 2.0a 2.0a-CD 2.0b 2.0c
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: February 5, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.