- 帖子
- 83
- 主題
- 17
- 精華
- 0
- 積分
- 105
- 點名
- 0
- 作業系統
- XP
- 軟體版本
- XP
- 閱讀權限
- 20
- 註冊時間
- 2010-12-28
- 最後登錄
- 2018-8-8
|
本帖最後由 小俠客 於 2016-12-13 10:56 編輯
回復 小俠客
stillfish00 發表於 2016-12-8 13:45 
沒想到原來可以用ERROR HANDLING的方法,謝謝大大。但我使用error handle時因為下面的小問題而出錯,所以我只能用sleep的方法,沒有用error handle
一個小問題,如果程式尋找沒有資料的編號,例如:「820」,網頁會有pop-up msgbox說:「Stock code 820 does not exist ... 」,所以我想先檢查html有沒有「does not exist 」的字眼,如果有我便跳到下一隻。
但可能因為pop-up msgbox的關係,我下一個loop走到「.Navigate "http://www.hkexnews.hk/sdw/search/search_sdw.asp"」時會顯示「-2147024726 VBAProject 'Navigate' 方法 ('IWebBrowser2' 物件) 失敗」- Sub test()
- Dim http As Object, i As Integer
- Set http = CreateObject("InternetExplorer.Application")
- With http
- For i = 1 To 100
- .Navigate "http://www.hkexnews.hk/sdw/search/search_sdw.asp"
- .Visible = True
- Do While .readyState <> 4
- DoEvents
- Loop
-
- .document.getelementbyid("ddlShareholdingDay").Value = 30
- .document.getelementbyid("ddlShareholdingMonth").Value = 11
- .document.getelementbyid("ddlShareholdingYear").Value = 2016
- .document.getelementbyid("txtStockCode").Value = Format(Cells(i, 1), "00000")
- .document.getelementbyid("btnSearch").Click
- sleep 2000
- result = http.document.body.innerhtml
-
- If InStr(result, "Network Error") > 0 Then
- MsgBox "Website error"
- GoTo out
- End If
-
- If InStr(result, "does not exist OR not available for enquiry") > 0 Then
- GoTo nextd
- End If
-
- Do Until InStr(result , "pnlResult") > 0
- DoEvents
- Loop
- Set A = .document.getelementbyid("pnlResult")
- result = A.innerhtml
- Do Until InStr(result, "Remarks:") > 0
- DoEvents
- result = A.innerhtml
- Loop
- Debug.Print Cells(i, 1)
- Next i
- End With
- End Sub
複製代碼 請問有沒有方法關掉IE的pop-up msgbox?謝謝 |
|