Results 1 to 7 of 7

ie automation run-time error

Threaded 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

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