Excel VBA查找字符串:错误2015 [英] Excel VBA find string : Error 2015

查看:1031
本文介绍了Excel VBA查找字符串:错误2015的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  Public Sub FindText(路径为字符串,文件为字符串)
Dim Found As Range

myText =test(

MacroBook = ActiveWorkbook.Name

打开文件
工作簿.Open path& file,ReadOnly:= True,UpdateLinks:= False
对于工作簿(文件)中的每个工作表。
使用ws

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

如果找不到就没有了然后
'做东西
'...

我在调试器中看到发现包含错误2015!文本我想要在公式中。



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

作为后续从Q到错误2015 发生,因为你的对于在表单中返回 #VALUE!错误。你可以使用 IsError 来处理:

pre $ If Not Found is Nothing Then
If IsError(Found)Then
'do sth
End If
End If


I have to following code snippet ...

  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
        ' ...

I see in the debugger that Found contains Error 2015! The sheet contains the text I want in the formula.

Any ideas why I'm getting the error?

Thanks

解决方案

As follow up from comments to the Q, Error 2015 occurs because your formula in the sheet returns #VALUE! error. You can handle it using IsError:

If Not Found Is Nothing Then
    If Not IsError(Found) Then
       ' do sth
    End If
End If

这篇关于Excel VBA查找字符串:错误2015的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆