Excel VBA查找字符串:错误2015

Rue*_*bit 3 excel vba find excel-vba

我必须遵循代码片段...

  Public Sub FindText(path As String, file As String)
    Dim Found As Range

    myText = "test("

    MacroBook = ActiveWorkbook.Name

    ' Open the File
    Workbooks.Open path & file, ReadOnly:=True, UpdateLinks:=False
    For Each ws In Workbooks(file).Worksheets
     With ws

       Set Found = .UsedRange.Find(What:=myText, LookIn:=xlFormulas, _
                      LookAt:=xlPart, MatchCase:=False)

       If Not Found Is Nothing Then
        ' do stuff
        ' ...
Run Code Online (Sandbox Code Playgroud)

我在调试器中看到Found包含Error 2015!工作表包含公式中我想要的文本.

任何想法为什么我收到错误?

谢谢

Dmi*_*liv 8

从注释到Q的后续跟踪,Error 2015因为工作表中的公式返回#VALUE!错误.您可以使用IsError以下方式处理:

If Not Found Is Nothing Then
    If Not IsError(Found) Then
       ' do sth
    End If
End If
Run Code Online (Sandbox Code Playgroud)