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: Add Worksheets For All The Given Dates Except Weekends and Copy The Common Template In Each Worksheet
- VBA-Excel: Create a new Word Document
- VBA-Excel: Consolidator – Merge or Combine Multiple Excel Files Into One
- VBA-Excel: Get ALL The Opened Internet Explorer (IE) using Microsoft Excel
- Excel-VBA : Open a MS Word Document using Excel File using Explorer Window.