Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

XL2000: Visual Basic Code to Use Instead of DIRECTORIES()


View products that this article applies to.

This article was previously published under Q213474

↑ Back to the top


Summary

This article contains sample Visual Basic for Applications code that you can use to duplicate the behavior of the DIRECTORIES() function that is included in the Microsoft Excel 4.0 Filefns.xla add-in.

NOTE: The Filefns.xla add-in is not included in Microsoft Excel 2000.

↑ Back to the top


More information

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs.
If you have limited programming experience, you may want to contact a Microsoft Certified Partner or Microsoft Advisory Services. For more information, visit these Microsoft Web sites:

Microsoft Certified Partners - https://partner.microsoft.com/global/30000104

Microsoft Advisory Services - http://support.microsoft.com/gp/advisoryservice

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS

Sample Visual Basic Code

' The main procedure calls dir_test and passes it to the specified
   ' directory.
   Sub main()
      'Calls dir_test and passes it the directory to check
      dir_test "c:\"
   End Sub
   ' The dir_test procedure returns an array of all subdirectories contained
   ' in the specified directory. To do this, it creates the array dir_array;
   ' dir_array is declared as Static to hold its values after the macro has
   ' finished.
   Sub dir_test(directory_text)
      'Dimensions a variable to hold the temp Directory name
      Dim temp_var As String
      'Dimensions a dynamic array to hold the Directory Array
      Static dir_array() As String
      'Check for backslash
      If Right(directory_text, 1) <> "\" Then
        directory_text = directory_text + "\"
      End If
      'Turns off Error Checking
   'Call the DIR function and returns the first item the Directory
   temp_var = Dir(directory_text, vbDirectory)
   'Initializes the variable for building the array
   counter = 0
'Set a loop until the DIR function returns
Do Until temp_var = ""
    'Temp_var stores the individual Directory name
    temp_var = Dir()
    'Checks to see if temp_var is an empty string
    If temp_var <> "" Then
       'The following code will create an array of the directories
       If GetAttr(directory_text & temp_var) And vbDirectory then
            'enlarge the array to hold a new item
            ReDim Preserve dir_array(counter)
            'add directory to the array
            dir_array(counter) = temp_var
            'This line just shows the variable was added to the array
            'You can comment this line out when using this function
            MsgBox dir_array(counter)
            'Increase counter to make room for the next directory
            counter = counter + 1
       End If
    End If
Loop
End Sub
				

↑ Back to the top


References

For more information about Filefns.xla and the Visual Basic equivalents for those functions, perform a query on the following phrases in the Microsoft Knowledge Base:
"Filefns.xla" and "Equivalent Visual Basic Statement"
To use the Microsoft Knowledge Base, browse to Support Online at the following Microsoft Web site:

↑ Back to the top


Keywords: KB213474, kbinfo, kbhowto

↑ Back to the top

Article Info
Article ID : 213474
Revision : 9
Created on : 11/23/2006
Published on : 11/23/2006
Exists online : False
Views : 264