VBA: Extract Folders & Sub Folders list to csv file


Sub ListFolder(sFolderPath As String)
    Dim FS As New FileSystemObject
    Dim FSfolder As Scripting.Folder
    Dim subfolder As Scripting.Folder
    Dim i As Integer
    Set FSfolder = FS.GetFolder(sFolderPath)
    For Each subfolder In FSfolder.SubFolders
        i = i + 1
    Open “C:\mycsvFile.csv” For Append Access Write As #1
    Print #1, “””” & subfolder + “\”””
    Close #1
         Debug.Print “””” & subfolder + “\”””
         ListFolder (subfolder)
    Next subfolder
    Set FSfolder = Nothing
End Sub

Call ListFolder(“C:\myFolder\”)


Posted on May 20, 2010, in VBA. Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: