什么是未定义的用户定义类型?

时间:2017-08-28 14:59:11

标签: excel-vba fso vba excel

以下是搜索文件夹以查找"要求"等文件夹的过程。当开始单步执行时,我收到一条错误消息"用户定义的类型未定义"。

我错过了什么?

Sub GetSubFolders()

Dim fso As New FileSystemObject, f As Folder, sf As Folder, myFile As File
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

1 个答案:

答案 0 :(得分:3)

您正在尝试使用FileSystemObject(早期绑定),而不在项目引用中指定对它的引用。

您需要添加Microsoft Scripting Runtime参考,如下面的屏幕截图所示:

enter image description here