Below is a procedure to search folder for a folder like "requirements". When beginning to step through I receive an error message because of FileSystemObject
:
User defined type not defined
What am I missing?
Sub GetSubFolders()
Dim f As Folder, sf As Folder, myFile As File
Dim fso As New FileSystemObject ' <=========== ERROR HERE
Set f = fso.GetFolder("C:\Users\C58227\Desktop\Projects\CRDs")
For Each sf In f.SubFolders
For Each mySubFolder In myFolder.SubFolders
For Each myFile In mySubFolder.Files
If myFile.Name Like "Requirements" Then
MsgBox myFile.Name
Exit For
End If
Next
MsgBox "Else"
Next
Next
End Sub
You are trying to use
FileSystemObject
(early binding) without specifying the reference to it in the Project References.You need to add
Microsoft Scripting Runtime
reference as can be seen in the screen-shot below: