2014-03-24 98 views
0

這是代碼,當我在下面描述的行上運行它和F8時,我會得到上述消息。必須先點擊確定按鈕17次才能退出。只適用於幾個網頁,其餘的(1000s)工作正常。前後行On Error Resume Next無效。任何想法如何代碼可以忽略味精並繼續?網頁留言。堆棧溢出行:1

Dim XMLHTTP As Object 
    Dim myURL As String 
    Dim html As Object 

    With CreateObject("MSXML2.serverXMLHTTP") 
    .Open "GET", myURL, False 
    .setRequestHeader "Content-Type", "text/xml" 
    .setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:25.0) Gecko/20100101 Firefox/25.0" 
    On Error Resume Next 
    .send 

    Set html = CreateObject("htmlfile") 
    html.body.innerHTML = .ResponseText 'getting the err msg here when I F8 on this line 
    End With 

回答

0

你試過

On Error Resume Err_Label 
Dim XMLHTTP As Object 
Dim myURL As String 
Dim html As Object 

With CreateObject("MSXML2.serverXMLHTTP") 
.Open "GET", myURL, False 
.setRequestHeader "Content-Type", "text/xml" 
.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:25.0) Gecko/20100101 Firefox/25.0" 

.send 

Set html = CreateObject("htmlfile") 
html.body.innerHTML = .ResponseText 'getting the err msg here when I F8 on this line 
End With 

Exit sub 

err_label: 
'any error logging/reporting goes here 
exit sub 
+0

你有兩個'退出sub',是正確的? – Sandy

+0

是的,如果出現錯誤,則轉至err_label,然後退出,如果代碼正常進行,則在觸發err_label之前退出。如果代碼是在一個函數中,那麼它是退出函數,而不是退出子 – jazza1000

+0

我得到了'On Error Resume Err_Label'的錯誤語法,所以我使用了'On Error GoTo Err_Label'。我再次在同一條線上得到了同樣的錯誤信息,必須點擊確定17次才能退出。不確定是否需要我在''任何錯誤日誌記錄/報告'這裏執行'... – Sandy