为什么在运行递归函数时出现“未定义用户定义类型”错误

时间:2019-06-06 15:16:36

标签: excel vba recursion

这是我用来检查目录中是否存在某个项目文件夹的代码。

Option Explicit
Public xCell As Range

Sub TestR()
Dim xTxt As String
Dim Rg As Range


xTxt = ActiveWindow.RangeSelection.Address
Set Rg = Application.InputBox("Please select project to check status!!!      ", "Lmtools", xTxt, , , , , 8)
If Rg Is Nothing Then
    MsgBox ("Nothing selected!!!")
    Exit Sub
End If
For Each xCell In Rg
   If xCell.Value <> "" Then
      Call Recurse("D:\")
   End If
Next

End Sub

Function Recurse(sPath As String) As String

Dim FSO As New FileSystemObject
Dim myFolder As Object
Dim mySubFolder As Object
Dim xStatus As String

Set myFolder = FSO.GetFolder(sPath)

For Each mySubFolder In myFolder.subfolders
    xStatus = mySubFolder.path
    If xStatus Like "*?\" & xCell.Value Then
        Cells(xCell.Row, xCell.Column + 1).Value = "Completed"
        Cells(xCell.Row, xCell.Column + 2).Value = xStatus
        GoTo nextiteration
    ElseIf xStatus Like "*?\" & xCell.Value & "\?*" Then
        Call reiterateFolder
    Else
        Cells(xCell.Row, xCell.Column + 1).Value = "Ongoing"
    End If
    Recurse = Recurse(mySubFolder.path)
Next

End Function

现在,当我运行代码时,它抛出一个错误,指出未定义用户定义的类型。

我在哪里犯了错误?

0 个答案:

没有答案