Microsoft KB Archive/78122

{|
 * width="100%"|

Word for Windows: Macro to List Files

 * }

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 &quot;a.&quot; 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$(&quot;What directory do you want to list ?&quot;) Spec$ = InputBox$(&quot;What file specification do you to look for?&quot;,, &quot;*.doc&quot;) On Error Goto errorfound ChDir Dir$ a$ = Files$(Spec$) FileNew .NewTemplate = 0, .Template = &quot;NORMAL&quot; FormatColumns .Columns = &quot;2&quot; While A$ <> &quot;&quot; Insert A$ filecount = filecount + 1 InsertPara a$ = Files$ Wend totalnum$ = Str$(filecount) dir$ = Files$(&quot;.&quot;) text$ = &quot;Total files in &quot; Insert text$ + dir$ + &quot; = &quot; + totalnum$ Goto exitmain errorfound: MsgBox &quot;An error occurred. Specified directory and file &quot; + \ &quot;specification should follow normal DOS standards.&quot;, 16 exitmain: End Sub For more information on directories and file specifications, consult your disk operating system (DOS) manual.