在实施ERP过程中,需要用到百度一下搜索,故写了以下代码,只需要将ieElement(0).Value = "卓丽栋"中的文字换成想要搜索的关键字即可。
Sub UseInternetExplorer()
On Error GoTo x
Dim ieApp As Object
Set ieApp = CreateObject("InternetExplorer.Application")
ieApp.Visible = True
ieApp.Navigate "http://WWW.BAIDU.COM"
Do While ieApp.Busy
Loop
Dim ieElement As Object
Set ieElement = ieApp.Document.getElementByID("f")
ieElement(0).Value = "卓丽栋"
'----利用循环语句在判断哪个表单元素是可以单击的,避免了出错现象
For i = 3 To 20
ieElement(i).Click
Next
x:
Debug.Print i - 1
End Sub
利用上述代码无需在工具--引用--中勾选Microsoft Internet controls。极大提高了实用性。
转载于:https://blog.51cto.com/softdiy/1202961