Microsoft KB Archive/306346

From BetaArchive Wiki
Knowledge Base


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 = "C:\My Documents\"
   sDocName = Dir(sMyDir & "*.DOC")
   While sDocName <> ""
      ' Print the file.
      Application.PrintOut FileName: = sMyDir & sDocName
      ' Get next file name.
      sDocName = Dir()
   Wend
End Sub
                

REFERENCES

For more information about how to use the sample code in this article, click the following article number to view the article in the Microsoft Knowledge Base:

290140 How to run the sample code for the Office XP programs from Knowledge Base articles


For more information about how to get help with Visual Basic for Applications, click the following article number to view the article in the Microsoft Knowledge Base:

305326 List of programming resources for Visual Basic for Applications



Additional query words: vb vbe inf VBA find files folders WD2002 WD2003

Keywords: kbdtacode kbhowto kbmacroexample kbprogramming KB306346