Macro to Generate Report of Files Found with FindFile Command

Last reviewed: July 30, 1997
Article ID: Q96566
The information in this article applies to:
  • Microsoft Word for Windows, versions 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a, 6.0c
  • Microsoft Word for Windows 95, version 7.0

SUMMARY

The Microsoft Word for Windows macro included in this article generates a report of the file names found in the Find File dialog box. Use this macro to return a list of the file names that match your Find File search parameters.

MORE INFORMATION

The macro displays the standard Find File dialog box; however, after you choose the Close button to exit the File Find dialog box, the macro asks the following question:

   Shall I insert a list of files found in a new document?

If you choose the Yes button, the macro creates a new Word for Windows document and inserts the file names of all files found.

CREATING THE MACRO

Use the steps appropriate for your version of Word.

Word 2.x

  1. On the File menu, click Template.

  2. Under "Store New Glossaries and Macros As," select the Global option button, then choose the OK button.

    NOTE: This step causes the new FileFind command to be stored in Normal.dot. If you want the new command to be template based, select the With Document Template option button instead of Global.

  3. On the Tools menu, click Macro.

  4. Under Show, select the Commands button. In the Macro Name box, select FileFind, then choose the Edit button.

  5. Delete the text in the macro-editing window and type the following macro text:

       Sub MAIN
       Dim dlg As FileFind
       GetCurValues dlg
       Dialog dlg
       NumFiles = CountFoundFiles()
       If Numfiles > 0 Then
       If MsgBox("Shall I insert a list of files found in a new document?" \
       ,292) = 0 Then
        Goto done
       End If
       Else
        Goto done   ' no files to report
       End If
       FileNew
       For x = 1 To Numfiles
        Insert FoundFileName$(x)
        InsertPara
       Next x
       done:  '<-- Note: Labels MUST be left aligned
       End Sub
    
    

  6. On the File menu, click Close. Choose the Yes button when prompted to save changes to the macro.

  7. On the File menu, click Save All, and when prompted, choose to save global glossary and command changes.

Word 6.x, 7.0, and 7.0a

  1. On the Tools menu, click Macro.

  2. In the Macro Name box, type a name like FileList, then choose the Edit button (Word 6.x) or the Create button (Word 7.x).

  3. Type the following macro text:

       Sub MAIN
       Dim dlg As FileFind
       GetCurValues dlg
       Dialog dlg
       NumFiles = CountFoundFiles()
       If Numfiles > 0 Then
       If MsgBox("Shall I insert a list of files found in a new document?" \
       ,292) = 0 Then
        Goto done
       End If
       Else
        Goto done   ' no files to report
       End If
       FileNew
       For x = 1 To Numfiles
        Insert FoundFileName$(x)
        InsertPara
       Next x
       done:  '<-- Note: the colon and labels MUST be left aligned!!
       End Sub
    
    

  4. On the File menu, click Close. Choose the Yes button when prompted to save changes to the macro.

  5. On the File menu, click Save All, and if prompted choose yes to save changes to the Normal template.

This macro causes the Print and Open buttons to become unavailable in the Find File dialog box.

WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

REFERENCES

"Microsoft Word for Windows User's Guide," version 2.0, pages 765, 784-786

Kbcategory: kbusage kbmacro KBSubcategory:


Additional query words: winword2 2.0 2.0a 2.0a-CD 2.0b 2.0c
word7 word6 7.0 word95 winword printout 6.0
Keywords : kbmacro kbusage
Version : 2.x 6.0 6.0a 6.0c 7.0
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.