(Solved) – VBA google search

(solved)-–-vba-google-search

I am learning to use excel VBA to automate a google search with my codes shown below. However, i always encounter ‘run time error 424: object required’ at the line indicated below. I have already declared searchtxt as my object yet error still occured. I tried to remove the searchtxt object declaration but it still does not work. Can someone help me to correct my code error so that i can do a google search in vba. Thank You

Sub google_search()
Dim searchtxt As Object, myie As Object

Set myie = CreateObject("internetexplorer.application")
With myie
    .Visible = True
    .Navigate "https:\www.google.com/search?fakebox-input="
    Do While .Busy
        DoEvents
    Loop
    Do While .readystate <> 4
        DoEvents
    Loop
End With

Set searchtxt = myie.document.getelementbyid("q")  'error occured here
Set searchtxt.Value = "excel vba"
myie.document.forms(0).submit

End Sub

Leave a Reply

Your email address will not be published. Required fields are marked *