Code Works on Excel 2016 but not works for 2010

Brass Contributor

I have created this below code which works on Excel 2016 but do not work on Excel 2010 an error appear that is run time error 13 type mismatch on Set doc = ie.document.

But i am unable to figure it out for Excel 2010 how it will fix.

One more thing i want to make it work faster then now. I will appreciate any help.

 

 

 

 

 

Sub Link()

Dim ie As New InternetExplorer
Dim doc As New HTMLDocument
Dim lastrow As Long
Dim ecoll As Object
Dim ecolla As Object
Dim link As Object
Dim t As Date

lastrow = Range("A" & Rows.Count).End(xlUp).Row

t = Now()
For i = 2 To lastrow

    ie.Visible = True
    ie.navigate "https://www.google.co.in/search?q=" & Cells(i, 1) & "&rnd=" & WorksheetFunction.RandBetween(1, 10000)
    
    Do
    DoEvents
    Loop Until ie.readyState = READYSTATE_COMPLETE
  
    Set doc = ie.document

    Set ecoll = doc.getElementById("rso")
    Set ecolla = ecoll.getElementsByTagName("H3")(0)
    Set link = ecolla.parentNode
    On Error Resume Next
    str_text = Replace(link.innerText, link.href, "")
    On Error Resume Next
    str_text = Replace(str_text, " ", "")
    
    Cells(i, 2) = link.href
    DoEvents
    
    Next
    ie.Quit
Set ie = Nothing

Debug.Print "done" & "Time taken : " & Format(Now() - t, "hh:mm:ss")
MsgBox "Ellapsed Time - " & Format(Now() - t, "hh:mm:ss")

End Sub

 

 

 

1 Reply
can you post the error message? Did you downgrade the reference of the Internet Explorer?