错误处理运行时错误不起作用
我不确定为什么 On Error goto
不处理以下错误。
我在单元格 T10
中设置了一个 Web 查询,我选择并更改 URL 并尝试将表格拉入工作表中。
我使用不同的 URL 执行此操作 20-30 次。
有时数据拉取时间太长或发生其他情况导致 Excel 无法获取数据...
在这些情况下,我想处理错误并继续。
但我仍然收到运行时错误“1004”,并且调试显示 .Refresh BackgroundQuery:=False
突出显示。
但是 On Error 不应该抓住它并转到工作表中更下面的 CardDataPullError
行吗?
我可以通过将 IP 更改为我的目标之外的其他内容来引发此问题。
On Error GoTo CardDataPullError
NodeIP = "192.168.210.4"
Range("T10").Select
With Selection.QueryTable
.Connection = "URL;http://" & NodeIP & ":21495/" & Card & "/ispCktDBPage"
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "3"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
On Error GoTo 0
'below is another section of code that highlights the cell red
'showing it had a problem pulling the data
GoTo SkipCard ' To skip error handler
CardDataPullError:
X = X
Cells(CardRow, CardCol).Interior.ColorIndex = 3 ' Red
SkipCard:
'other reasons to skip to
I am not sure why the On Error goto
does not handle the following error.
I have a web query set up in cell T10
that I select and change the URL and attempt to pull a table into the sheet.
I do this 20-30 times with different URL's.
Sometimes the data pull takes too long or something else happens that won't allow excel to get the data...
In those cases I want to handle the error and continue.
But I am still getting the runtime error '1004' and debug shows .Refresh BackgroundQuery:=False
highlighted.
But shouldn't the On Error grab that and goto line CardDataPullError
further down in the sheet?
I can invoke this issue by changing the IP to something other that my target.
On Error GoTo CardDataPullError
NodeIP = "192.168.210.4"
Range("T10").Select
With Selection.QueryTable
.Connection = "URL;http://" & NodeIP & ":21495/" & Card & "/ispCktDBPage"
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "3"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
On Error GoTo 0
'below is another section of code that highlights the cell red
'showing it had a problem pulling the data
GoTo SkipCard ' To skip error handler
CardDataPullError:
X = X
Cells(CardRow, CardCol).Interior.ColorIndex = 3 ' Red
SkipCard:
'other reasons to skip to
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您忘记将
resume
放入CardDataPullError
错误处理程序中。因此该错误不会被处理。
更改代码如下:
You forgot to put
resume
in theCardDataPullError
error handler.Therefore the error is not handled.
Change the code as follows: