| Be the first user to complete this post  | Add to List | 
VBA-Excel: Perform Google Search on Internet Explorer using Microsoft Excel
This article will teach you about how you can perform a google search on Internet Explorer using Microsoft Excel.
Steps:
- Create the object of Shell Application
- Get all the windows using shellobject.Windows
- Navigate all the windows
- check if window is Internet Explorer.
- if window is IE then check if it is Google Search browser and store the object
- Get the Page object of Google Search window.
- Identify the objects on the Page using “GetElementById” and "getElementsByName"
- Put the search text
- Wait for 3-4 secs
- Click the Search button
Create the object of Shell Application
Set objShell = CreateObject("Shell.Application")
Get all the windows using shellobject.Windows
Set objAllWindows = objShell.Windows
Navigate all the windows
For Each ow In objAllWindows
check if window is Internet Explorer
If (InStr(1, ow, "Internet Explorer", vbTextCompare)) Then
if window is IE then check if it is Google Search browser and store the object
If (InStr(1, ow.locationURL, "www.google.", vbTextCompare)) Then
Set objGoogle = ow
End If
Get the Page object of Google Search window.
Set objPage = objGoogle.Document
Identify the objects on the Page using “GetElementById” and " getElementsByName"
Set SearchEditB = objPage.getElementByID("gbqfq")
Set Search = objPage.getElementsByName("btnG")
Put the search text
SearchEditB.Value = "Excel macro Sumit Jain"
Wait for 3-4 secs
FnWait (5)
Click the Search button
Search(0).Click
Complete Code:
Sub googleSearch()
    Set objShell = CreateObject("Shell.Application")
    Set objAllWindows = objShell.Windows
    For Each ow In objAllWindows
        If (InStr(1, ow, "Internet Explorer", vbTextCompare)) Then
            If (InStr(1, ow.locationURL, "www.google.", vbTextCompare)) Then
                Set objGoogle = ow
            End If
        End If
    Next
    If objGoogle Is Nothing Then
    Else
        Set objPage = objGoogle.Document
        Set SearchEditB = objPage.getElementByID("gbqfq")
        SearchEditB.Value = "Excel macro Sumit Jain"
        FnWait (5)
        Set Search = objPage.getElementsByName("btnG")
        Search(0).Click
    End If
End Sub
Function FnWait(intTime)
    newHour = Hour(Now())
    newMinute = Minute(Now())
    newSecond = Second(Now()) + intTime
    waitTime = TimeSerial(newHour, newMinute, newSecond)
    Application.Wait waitTime
End Function


Also Read:
- VBA-Excel: Create and Save the Word document
- VBA-Excel: Working with Bookmarks- Insert text After Bookmark
- Excel-VBA : Prevent Changing the WorkSheet Name
- VBA-Excel — AttachmentFetcher — Download all the Attachments from All the Mails of Specific Subject in Microsoft Outlook .
- VBA-Excel: Read Data from XML File
 
    