Skip to main content

Folders collection

Table of contents
  1. Examples

Collection of all Folder objects contained within a Folder object.


The following code illustrates how to get a Folders collection and how to iterate the collection by using the For Each...Next statement.

Sub ShowFolderList(folderspec)
    Dim fso As Object, f As Object, f1, fc As Object, msg As String
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.GetFolder(folderspec)
    Set sf = f.SubFolders
    For Each f1 In sf
        msg = msg & f1.Name
        msg = msg & vbCrLf
    Debug.Print msg
End Sub

Run the following code in the Immediate Window to test this macro:



floder A
hidden floder

Leave a comment

Your email address will not be published. Required fields are marked *

Format your code: <pre><code class="language-vba">place your code here</code></pre>