Macro to Print All Documents in a Directory

Last reviewed: July 30, 1997
Article ID: Q107687
The information in this article applies to:
  • Microsoft Word for Windows, versions 6.0, 6.0a, 6.0c
  • Microsoft Word for Windows 95, version 7.0

SUMMARY

The following Word 6.0 for Windows macro can be used to print all the documents found in an MS-DOS folder.

MORE INFORMATION

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.

Sub MAIN
doc$ = Files$("*.DOC") While doc$ <> ""
 FilePrint .FileName = doc$
 doc$ = Files$()
Wend
End Sub

The above macro uses the Files$() function and FilePrint statement to print the documents with a .DOC file extension in the current folder.

You can customize the above macro to print files from a specified folder by adding a ChDir statement at the top of the macro.

   ChDir "C:\WinWord"   'changes the current folder to C:\WINWORD

Note: By specifying "*.DOC" on the first iteration and omitting it thereafter, you can use the Files$() function to generate a list of files. If no files match, an empty string ("") is returned.

This same idea can be used to create a list of file names in the current folder. The following example macro creates a new document with the file names from the current folder.

Sub MAIN
FileNewDefault doc$ = Files$("*.*") While doc$ <> ""
 Insert doc$
 InsertPara
 doc$ = Files$()
Wend
End Sub

Kbcategory: kbusage kbmacro KBSubcategory:


Additional query words: 6.0 print document FilePrint word6 word7
6.0a 6.0c 7.0 word95 winword Files$() FilePrintAll
Version : 6.0 6.0a 6.0c 7.0
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: July 30, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.