[VBA ] 利用EXCEL VBA 2007抓取網頁資料之問題
想請問一下…我在用EXCEL 2003時
可以透過InternetExplorer這個去抓取網頁資料!
但是換到excel2007時,卻無法使用耶!
想請問一下 版上的高手
該怎麼解決呢?
程式碼如下…
Dim myIE As InternetExplorer
Dim YearStr As String
Dim MonthStr As String
Dim DayStr As String
Dim ContractStr As String
Dim i As Integer
Dim j As Integer
Dim k As Integer
YearStr = "2009"
MonthStr = "3"
DayStr = "2"
ContractStr = "TX"
Set myIE = New InternetExplorer
With myIE
.Visible = True
.Navigate "http://www.taifex.com.tw/chinese/3/3_1_1.asp"
Do While .Busy
Loop
Do Until .ReadyState = READYSTATE_COMPLETE
Loop
End With
With myIE.Document
For i = 0 To .forms("myform").Length - 1
If .forms("myform")(i).Name = "syear" Then '設定年份
For k = 0 To .forms("myform")(i).Length - 1
If .forms("myform")(i).Options(k).Value = YearStr Then
.forms("myform")(i).Options(k).Selected = True
End If
Next k
End If
next i
end with
上面這段程式碼在2003執行時 是沒有問題的
但到了2007
他卻出現了
執行階段錯誤
automation錯誤
用戶端中斷了已啟動物件的連線
他會自動開啟ie
但我關掉以後他就出現了此訊息!
若我把開啟ie那邊的do until loop迴圈拿掉
他又出現了
遠端伺服器不存在或無法使用 這個錯誤訊息
想請問版上的高手 該怎麼解決呢?@@感謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.173.98.126
推
04/09 01:37, , 1F
04/09 01:37, 1F