Word for Windows: Macro to List Files

ID: Q78122


The information in this article applies to:
  • Microsoft Word for Windows, versions 1.0, 1.1, 1.1a, 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a, 6.0c


SUMMARY

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

Additional query words: 1.0 1.1 1.x 2.0 word6 winword winword2

Keywords :
Version : WINDOWS:1.0,1.1,1.1a,2.0,2.0a,2.0a-CD,2.0b,2.0c,6.0,6.0a,6.0c
Platform : WINDOWS
Issue type :


Last Reviewed: December 22, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.