• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 312
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

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