Microsoft KB Archive/306346

= Sample macro to print all Word documents found in a folder =

Article ID: 306346

Article Last Modified on 1/31/2007

-

APPLIES TO


 * Microsoft Office Word 2003
 * Microsoft Word 2002 Standard Edition

-



This article was previously published under Q306346





For a Microsoft Word 2000 version of this article, see 201993.



For a Microsoft Word 98 version of this article, see 183867.



For a Microsoft Word 97 version of this article, see 180513.



SUMMARY
This article contains a sample Microsoft Visual Basic for Applications routine (macro) that can be used to print all Microsoft Word documents that are found in the specified folder.



MORE INFORMATION
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

The following sample macro prints all Word documents that are found in the specified folder. Sub ListDocNamesInFolder Dim sMyDir As String Dim sDocName As String ' The path to obtain the files. sMyDir = &quot;C:\My Documents\&quot; sDocName = Dir(sMyDir & &quot;*.DOC&quot;) While sDocName <> &quot;&quot; ' Print the file. Application.PrintOut FileName: = sMyDir & sDocName ' Get next file name. sDocName = Dir Wend End Sub

