Microsoft KB Archive/107687

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 17:44, 20 July 2020 by X010 (talk | contribs) (Text replacement - ">" to ">")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Base

Macro to Print All Documents in a Directory

Article ID: 107687

Article Last Modified on 8/16/2005


  • Microsoft Word 6.0 Standard Edition
  • Microsoft Word 6.0a
  • Microsoft Word 6.0c
  • Microsoft Word 95 Standard Edition

This article was previously published under Q107687


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


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.


doc$ = Files$("*.DOC")
While doc$ <> ""
 FilePrint .FileName = doc$
 doc$ = Files$()

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.


doc$ = Files$("*.*")
While doc$ <> ""
 Insert doc$
 doc$ = Files$()

End Sub

Kbcategory: kbusage kbmacro

Additional query words: 6.0 print document FilePrint word6 word7 7.0 word95 winword Files$() FilePrintAll

Keywords: KB107687