0

我想使用 VBA 来运行 Google 搜索。能够一次将一个字母输入到 Google 搜索栏中对我来说很重要。这是我当前的代码:

myie.document.all("q").Value = "cheese"

这将在一个完整的时间间隔内将搜索词“奶酪”加载到搜索栏中。我希望以更自然的人性化方式进行搜索;在搜索栏中输入“c”,然后输入“h”,然后输入“e”等...

任何帮助表示赞赏

4

1 回答 1

0

这是你正在尝试的吗?

Option Explicit

Private Sub CommandButton1_Click()
    WebBrowser1.Navigate "Google.com"
End Sub

Private Sub CommandButton2_Click()
    Dim strtext As String
    Dim i As Long

    strtext = "cheese"

    For i = 1 To Len(strtext)
        WebBrowser1.Document.all("q").Value = WebBrowser1.Document.all("q").Value & Mid(strtext, i, 1)
        Wait 1
    Next i
End Sub

Private Sub Wait(ByVal nSec As Long)
    nSec = nSec + Timer
    While nSec > Timer
        DoEvents
    Wend
End Sub

如果您对键入时显示的所有结果感到困扰,那么您也可以使用它

Sub Sample()
    Dim IE As Object

    Set IE = CreateObject("InternetExplorer.Application")

    IE.Visible = True

    '~~> Choose one of the below
    IE.Navigate ("http://www.google.com/#hl=en&q=" & "Cheese") '<~~ US
    IE.Navigate ("http://www.google.co.uk/#hl=en&q=" & "Cheese") '<~~ UK
    IE.Navigate ("http://www.google.co.in/#hl=en&q=" & "Cheese") '<~~ INDIA
End Sub
于 2012-05-29T14:43:03.580 回答