作者:iamlaosong
用VBA编程实现自动读取网页数据,在读取过程中关闭网页时遇到这样一个错误:“ 方法quit作用IWebBrowser2失败”,无法执行quit方法,但其它属性没有问题,百思未得其解,其源代码如下:
Sub login3()
Dim ie1 As Object
lineno = [A65536].End(xlUp).Row '行数
For row1 = 2 To lineno
ems_id = Trim(Cells(row1, 1))
Set ie1 = CreateObject("InternetExplorer.Application")
ie1.Visible = True
ie1.navigate "http://10.3.10.83/ems/newsystem/thesecond/ttq/ttqMailquery.jsp"
Do Until ie1.Readystate = 4
DoEvents
Loop
ie1.document.Forms(0).All("mailNum").Value = ems_id
ie1.document.Forms(0).submit
If MsgBox("第" & row1 - 1 & "个邮件查询完毕,继续...", vbOKCancel, "AHEMS:iamlaosong") = vbCancel Then Exit Sub
ie1.Quit ' 此句报错
'Debug.Print ie1.document.DocumentElement.outerHTML ' 显示网页源代码
'Debug.Print ie1.document.body.innertext ' 显示网页文本信息
'rethtml = ie1.document.DocumentElement.outerHTML
Next row1
End Sub
结论:该方法可以关闭IE浏览器,其它浏览器是否可行,需要测试。
【VBA研究】方法quit作用于IWebBrowser2失败怎么办
原文:http://blog.csdn.net/iamlaosong/article/details/44773883