+ Reply to Thread
Results 1 to 5 of 5

Google Search VBA - Issue

  1. #1
    Registered User
    Join Date
    01-12-2019
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    3

    Post Google Search VBA - Issue

    Hi All,

    First time poster.
    I've had an excel document that utilised VBA to search Google a list of terms and then return the number of results for this term. This document has worked for many months/years, but recently has stopped working and I cannot figure out why!
    Any support on getting this back up and running would be greatly appreciated.

    The VBA string is:

    Sub SearchGoogle()
    Dim ie As Object
    Dim form As Variant
    Dim button As Variant
    Dim LR As Integer
    Dim var As String
    Dim var1 As Object
    LR = Cells(Rows.Count, 1).End(xlUp).Row
    For x = 2 To LR
    var = Cells(x, 1).Value
    Set ie = CreateObject("internetexplorer.application")
    ie.Visible = True
    With ie
    .Visible = True
    .navigate "google"
    While Not .readyState = READYSTATE_COMPLETE
    Wend
    End With
    'Wait some to time for loading the page
    While ie.Busy
    DoEvents
    Wend
    Application.Wait (Now + TimeValue("0:00:02"))
    ie.document.getElementById("lst-ib").Value = var
    'Here we are clicking on search Button
    Set form = ie.document.getElementsByTagName("form")
    Application.Wait (Now + TimeValue("0:00:02"))
    Set button = form(0).onsubmit
    form(0).submit
    'wait for page to load
    While ie.Busy
    DoEvents
    Wend
    Application.Wait (Now + TimeValue("0:00:02"))
    Set var1 = ie.document.getElementById("resultStats")
    Cells(x, 2).Value = var1.innerText
    ie.Quit
    Set ie = Nothing
    Next x

    End Sub
    Would really appreciate any support with this issue
    *Note had to change the URL of google to just google for this post as unable to post links.

    Kind regards,

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    18,932

    Re: Google Search VBA - Issue

    Any chance you could upload a sample workbook?

    Click on GO ADVANCED, scroll down and click Manage Attachments.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    01-12-2019
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    3

    Re: Google Search VBA - Issue

    Think it should be attached now
    Attached Files Attached Files

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    18,932

    Re: Google Search VBA - Issue

    When I step through the code I get an 'Object required' error here.
    Please Login or Register  to view this content.
    That error suggests to me that, for whatever reason, an element with the id 'lst-ib' isn't being found.

  5. #5
    Registered User
    Join Date
    01-12-2019
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    3
    Quote Originally Posted by Norie View Post
    When I step through the code I get an 'Object required' error here.
    Please Login or Register  to view this content.
    That error suggests to me that, for whatever reason, an element with the id 'lst-ib' isn't being found.

    I see, do you have any idea what to replace this with? I guess maybe this has changed and now broken the string.

    Would really appreciste any support

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1