Microsoft KB Archive/121890

= WD: Macro: Displaying a List of Directories =

Article ID: 121890

Article Last Modified on 1/19/2007

-

APPLIES TO


 * Microsoft Word 6.0 Standard Edition
 * Microsoft Word 6.0a
 * Microsoft Word 6.0c
 * Microsoft Word 6.0 Standard Edition
 * Microsoft Word 95 Standard Edition
 * Microsoft Word 95a
 * Microsoft Word 6.0 for Macintosh
 * Microsoft Word 6.01 for Macintosh
 * Microsoft Word 98 for Macintosh
 * Microsoft Word 97 Standard Edition

-



This article was previously published under Q121890



SUMMARY
The Microsoft WordBasic CountDirectories and GetDirectory$ functions can be used to assemble a list of directory names within the current directory.

For information and examples about how to perform this function in Word 97 for Windows or Word 98 Macintosh Edition, from the Visual Basic for Applications Editor, click the Office Assistant, type Dir, click Search, and then click to view "Dir."

NOTE: If the Assistant is hidden, click the Office Assistant button on the Standard toolbar. If Microsoft Help is not installed on your computer, please see the following article in the Microsoft Knowledge Base:

120802 Office: How to Add/Remove a Single Office Program or Component



MORE INFORMATION
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 expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

The following example macro inserts the directory names from the current directory into a new document window: Sub MAIN FileNewDefault num = CountDirectories For i = 1 To num Insert GetDirectory$(i) InsertPara Next i  End Sub The following example macro determines how many directories stem from the current directory and defines an array named SubDirs$ to hold the directory names: Sub MAIN REM Define an array for the directory names Dim subdirs$(CountDirectories) subdirs$(0) = "[..]" For i = 1 To CountDirectories subdirs$(i) = LCase$(GetDirectory$(i)) Next REM Sort the array of directories and display them in a list box. SortArray subdirs$ Begin Dialog UserDialog 396, 154, "Directories Available" OKButton 254, 88, 88, 21 CancelButton 254, 113, 88, 21 ListBox 18, 21, 215, 114, subdirs$, .ListBox1 End Dialog Dim dlg As UserDialog n = Dialog(dlg) End Sub NOTE: The disk that accompanies the Word Developer's Kit includes a macro that allows you to browse through files in any directory. The macro uses a dynamic dialog box to display a file and directory list similar to the Open dialog box in Word. The macro is named ch05ex06FileBrowser and is located in the Examples.dot file.

