如何使用 VBA 单击“Google 搜索”按钮

时间:2021-02-16 13:52:33

标签: excel vba

我正在尝试使用 (2007) Excel VBA 打开 Internet Explorer,导航到 google.com,将 Excel 电子表格中的文本字符串输入 google.com 搜索表单,然后单击“Google 搜索”按钮.

我使用的代码打开 Internet Explorer,导航到 google.com,然后将 Excel 文本字符串很好地输入到 Google 搜索表单中。但我似乎无法让我的代码点击“谷歌搜索”按钮。有什么建议吗?

这是我得到的代码:

Sub FillInternetForm()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.navigate "http://www.google.com"
IE.Visible = True
While IE.Busy
DoEvents
Wend
IE.document.all("q").Value = ThisWorkbook.Sheets("Sheet1").Range("A1")
IE.document.all("btnK").Click
End Sub

1 个答案:

答案 0 :(得分:1)

如果您觉得不是绝对需要点击搜索按钮,您也可以只更改 URL 以包含搜索参数。在这种情况下,导航到 URL 即可“执行”搜索,而无需按下按钮。 有关详细信息,请参阅此链接: https://webapps.stackexchange.com/questions/39818/how-should-i-write-the-url-for-a-specific-google-search-query