• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 305
  • Last Modified:

What is the VBA to read subfolder names?

Hi Experts,

What is the VBA to read subfolder names in the main folder?

Thanks
0
kosenrufu
Asked:
kosenrufu
  • 2
1 Solution
 
Rey Obrero (Capricorn1)Commented:
place this codes in a regular module
*add to your references microsoft scripting runtime

* to use the codes

call getfolders("c:\mymainfolder")

Sub GetFolders(sPath As String)

Dim fso As Scripting.FileSystemObject
Dim srcFolder As Scripting.Folder, sbFolder As Scripting.Folder
Dim fileItem As Scripting.File

Set fso = New Scripting.FileSystemObject
Set srcFolder = fso.GetFolder(sPath)

For Each sbFolder In srcFolder.SubFolders
   
    Debug.Print sbFolder.Name
   
Next

End Sub


0
 
kosenrufuAuthor Commented:
capricorn1:

Getting the error, "User-defined type not found" in the line:

Dim fso As Scripting.FileSystemObject

Thanks
0
 
Rey Obrero (Capricorn1)Commented:
did you see this line above

*add to your references microsoft scripting runtime
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now