作者ken8868 (freedom)
看板Visual_Basic
标题[VBA ] 利用EXCEL VBA 2007抓取网页资料之问题
时间Wed Apr 1 23:27:23 2009
想请问一下…我在用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
1F:推 diolin:改用 xmlhttp object 写吧,比较灵活,也好处理 04/09 01:37