How to solve the error User defined type not defined?
Asked Answered
C

1

6

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
Carpus answered 28/8, 2017 at 14:59 Comment(0)
G
15

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:

enter image description here

Gouty answered 28/8, 2017 at 15:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.