WD: Macro: Displaying a List of DirectoriesLast reviewed: February 3, 1998Article ID: Q121890 |
The information in this article applies to:
SUMMARYThe 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:
ARTICLE-ID: Q120802 TITLE : Office: How to Add/Remove a Single Office Program or Component MORE INFORMATIONWARNING: 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 SubThe 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 SubNOTE: 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.
REFERENCES"Microsoft Word Developer's Kit," version 6.0, page 128-130
|
Additional query words: GetDirectory$() Array Subdirectory
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |