返回列表 上一主題 發帖

[發問] 擷取web下拉式表單

回復 1# carzyindex
以錢櫃KTV網頁為例,門市查詢的下拉選單內容
http://www.cashboxparty.com/ktv/ktv_index.asp
  1. Sub GetWebObj()
  2. Dim MyURL$, Ar()
  3. MyURL = "http://www.cashboxparty.com/ktv/ktv_index.asp"
  4. Set MyIE = Nothing
  5. Set MyIE = CreateObject("InternetExplorer.Application")
  6.             With MyIE
  7.                 .Navigate MyURL
  8.                 Do While .Busy Or .ReadyState <> 4
  9.                     DoEvents
  10.                 Loop
  11.                 .Visible = False
  12.                For i = 0 To .document.all("dept").Options.Length - 1
  13.                ReDim Preserve Ar(i)
  14.                Ar(i) = .document.all("dept").Options(i).innerText
  15.                Next
  16.                .Quit
  17.             End With
  18. MsgBox Join(Ar, Chr(10))
  19. End Sub
複製代碼
學海無涯_不恥下問

TOP

本帖最後由 Hsieh 於 2011-3-11 10:47 編輯

回復 6# FAlonso

直接寫入儲存格,不須先寫入陣列
這重點只是取出下拉選單內容的語法
  1. Sub abc()
  2. Dim myURL As String,i As Integer
  3. Set myie = Nothing
  4. Set myie = CreateObject("internetexplorer.application")
  5. myURL = "http://tw.weather.yahoo.com/"
  6. With myie
  7. .Navigate myURL
  8. .Visible = False
  9. Do While .Busy And .ReadyState <> READYSTATE_COMPLETE
  10. DoEvents
  11. Loop
  12. For i = 0 To .Document.all("select").Options.Length - 1
  13. Cells(i + 1, 1) = .Document.all("select").Options(i).innertext
  14. Next
  15. .Quit
  16. End With
  17. End Sub
複製代碼
學海無涯_不恥下問

TOP

回復 8# FAlonso


    這個原因可能是因為前一次的myie變數未被卸載所致
所以我在程式開頭就先
Set myie = Nothing
然後再去建立物件
Set myie = CreateObject("internetexplorer.application")
學海無涯_不恥下問

TOP

        靜思自在 : 君子立恆志,小人恆立志。
返回列表 上一主題