2011-04-12 66 views
2

我不知道爲什麼On Error goto不處理以下錯誤。
我在單元格T10中設置了一個網頁查詢,我選擇並更改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 

回答

4

你忘了resumeCardDataPullError錯誤處理程序。
因此不處理錯誤。

如下更改代碼:

CardDataPullError: 
    X = X 
    Cells(CardRow, CardCol).Interior.ColorIndex = 3 ' Red 
    Resume SkipCard: