Word for Windows: Macro to List Files

Last reviewed: July 30, 1997
Article 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

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


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 30, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.