利用vba 控制ie 讓搜索引擎和excel結合

在實施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。極大提高了實用性。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章