+ Reply to Thread
Results 1 to 7 of 7

ie automation run-time error

Hybrid View

  1. #1
    Registered User
    Join Date
    01-22-2013
    Location
    Waterloo, ON
    MS-Off Ver
    Excel 2013
    Posts
    4

    ie automation run-time error

    Hello all,

    I am trying to run a macro to search the string in column a into Google, retrieve the URL of the first search result, and place the resulting title and url into columns c and d, respectively. I retrieved the code for this macro from some answers site, but I understand the gist of it. The macro tends to work for a little while - say 40 rows - but then returns a run-time error. After the run-time error, if I stop the macro and immediately run again, the error will re-occur until I wait a certain amount of time. The error reads: "Run-time error '-2147024891 (80070005)': Access is denied." Is there a way to beat this error?

    Sub xmlHttp()
    
        Dim URl As String, lastRow As Long
        Dim xmlHttp As Object, html As Object, objResultDiv As Object, objH3 As Object, link As Object
    
    
        lastRow = Range("A" & Rows.Count).End(xlUp).Row
    
        For i = 2 To lastRow
    
            URl = "https://www.google.co.in/search?q=" & Cells(i, 1)
    
            Set xmlHttp = CreateObject("MSXML2.XMLHTTP")
            xmlHttp.Open "GET", URl, False
            xmlHttp.setRequestHeader "Content-Type", "text/xml"
            xmlHttp.send
    
            Set html = CreateObject("htmlfile")
            html.body.innerHTML = xmlHttp.ResponseText
            Set objResultDiv = html.getelementbyid("rso")
            Set objH3 = objResultDiv.getelementsbytagname("H3")(0)
            Set link = objH3.getelementsbytagname("a")(0)
    
    
            str_text = Replace(link.innerHTML, "<EM>", "")
            str_text = Replace(str_text, "</EM>", "")
    
            Cells(i, 2) = str_text
            Cells(i, 3) = link.href
        Next
    End Sub
    Thanks!
    Attached Files Attached Files

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

    Re: ie automation run-time error

    You seem to be creating a lot of objects and then not re-using them, dismissing them, setting them to Nothing.

    I can only think that's going to mean that as the code runs you will be leaving a whole lot of objects just kind of floating about unused.

    That might not be the root of the problem though, have you checked if you get the error you describe when you search on a specific term/terms or try and access a particular URL/page?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    01-22-2013
    Location
    Waterloo, ON
    MS-Off Ver
    Excel 2013
    Posts
    4

    Re: ie automation run-time error

    Thanks for your response.
    Well I don't think it's a specific term/terms, because the code worked for the first 30-40 terms, then gave me a run-time error, but when I ran it again a couple hours later, the code continued on lines 40-60ish, then gave me another run-time error, and I ran it again until line 90ish. No specific search string seems to have given an error, but it seems after a certain amount of time sending the xml request, my access is denied...

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: ie automation run-time error

    It's possible that you are being blocked, automation of google searches in this way is strictly against their terms and conditions - it's possible that they therefore put a limit on the number of requests that you can make in a given time period

  5. #5
    Registered User
    Join Date
    01-22-2013
    Location
    Waterloo, ON
    MS-Off Ver
    Excel 2013
    Posts
    4

    Re: ie automation run-time error

    Hi Kyle, That does seems a plausible reason for getting denied access. However, I have made Google searches in IE immediately after getting the run-time error, with no such issue...

  6. #6
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: ie automation run-time error

    I suspect it's the frequency of requests, currently you are making requests as fast as vba allows, google doesn't like this, making a request then in internet explorer wil then have a different request profile and be much slower.

  7. #7
    Registered User
    Join Date
    01-22-2013
    Location
    Waterloo, ON
    MS-Off Ver
    Excel 2013
    Posts
    4

    Re: ie automation run-time error

    Ah I see. Thank you.

+ 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