gpt4 book ai didi

vba - Excel VBA查找字符串: Error 2015

转载 作者:行者123 更新时间:2023-12-01 06:20:24 26 4
gpt4 key购买 nike

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

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

我在调试器中看到 Found 包含错误 2015!该工作表包含我想要的公式中的文本。

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

谢谢

最佳答案

作为对 Q 的评论的跟进,Error 2015发生是因为工作表中的公式返回 #VALUE!错误。您可以使用 IsError 处理它:

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

关于vba - Excel VBA查找字符串: Error 2015,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22014093/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com