Word for Windows: Macro to List Files

ID: Q78122

The information in this article applies to:

The following macro displays a listing of files for any specified directory. It also allows you to specify files you want to search for. For example, if you type a*.*, the macro searches for all files that begin with the letter "a." Microsoft Word for Windows places the list of files in a document. You can save this document for future reference.

Sub MAIN
On Error Resume Next Dir$ = InputBox$("What directory do you want to list ?") Spec$ = InputBox$("What file specification do you to look for?",, "*.doc") On Error Goto errorfound ChDir Dir$ a$ = Files$(Spec$) FileNew .NewTemplate = 0, .Template = "NORMAL" FormatColumns .Columns = "2" While A$ <> ""
 Insert  A$
 filecount = filecount + 1
 InsertPara
 a$ = Files$()
Wend totalnum$ = Str$(filecount) dir$ = Files$(".") text$ = "Total files in " Insert text$ + dir$ + " = " + totalnum$ Goto exitmain errorfound: MsgBox "An error occurred. Specified directory and file " + \ "specification should follow normal DOS standards.", 16 exitmain:
End Sub

For more information on directories and file specifications, consult your disk operating system (DOS) manual.

REFERENCES

"Microsoft Word For Windows and OS/2 Technical Reference", page 178

Kbcategory: kbusage kbmacro KBSubcategory: Additional query words: 1.0 1.1 1.1a 1.x 2.0 word6 winword winword2

Version           : 1.x 2.x 6.0 6.0a 6.0c
Platform          : WINDOWS

Last Reviewed: July 30, 1997