Code Works on Excel 2016 but not works for 2010

%3CLINGO-SUB%20id%3D%22lingo-sub-2693298%22%20slang%3D%22en-US%22%3ECode%20Works%20on%20Excel%202016%20but%20not%20works%20for%202010%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2693298%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20created%20this%20below%20code%20which%20works%20on%20Excel%202016%20but%20do%20not%20work%20on%20Excel%202010%20an%20error%20appear%20that%20is%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Erun%20time%20error%2013%20type%20mismatch%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eon%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3ESet%20doc%20%3D%20ie.document.%3C%2FP%3E%3CP%3EBut%20i%20am%20unable%20to%20figure%20it%20out%20for%20Excel%202010%20how%20it%20will%20fix.%3C%2FP%3E%3CP%3EOne%20more%20thing%20i%20want%20to%20make%20it%20work%20faster%20then%20now.%20I%20will%20appreciate%20any%20help.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3ESub%20Link()%0A%0ADim%20ie%20As%20New%20InternetExplorer%0ADim%20doc%20As%20New%20HTMLDocument%0ADim%20lastrow%20As%20Long%0ADim%20ecoll%20As%20Object%0ADim%20ecolla%20As%20Object%0ADim%20link%20As%20Object%0ADim%20t%20As%20Date%0A%0Alastrow%20%3D%20Range(%22A%22%20%26amp%3B%20Rows.Count).End(xlUp).Row%0A%0At%20%3D%20Now()%0AFor%20i%20%3D%202%20To%20lastrow%0A%0A%20%20%20%20ie.Visible%20%3D%20True%0A%20%20%20%20ie.navigate%20%22https%3A%2F%2Fwww.google.co.in%2Fsearch%3Fq%3D%22%20%26amp%3B%20Cells(i%2C%201)%20%26amp%3B%20%22%26amp%3Brnd%3D%22%20%26amp%3B%20WorksheetFunction.RandBetween(1%2C%2010000)%0A%20%20%20%20%0A%20%20%20%20Do%0A%20%20%20%20DoEvents%0A%20%20%20%20Loop%20Until%20ie.readyState%20%3D%20READYSTATE_COMPLETE%0A%20%20%0A%20%20%20%20Set%20doc%20%3D%20ie.document%0A%0A%20%20%20%20Set%20ecoll%20%3D%20doc.getElementById(%22rso%22)%0A%20%20%20%20Set%20ecolla%20%3D%20ecoll.getElementsByTagName(%22H3%22)(0)%0A%20%20%20%20Set%20link%20%3D%20ecolla.parentNode%0A%20%20%20%20On%20Error%20Resume%20Next%0A%20%20%20%20str_text%20%3D%20Replace(link.innerText%2C%20link.href%2C%20%22%22)%0A%20%20%20%20On%20Error%20Resume%20Next%0A%20%20%20%20str_text%20%3D%20Replace(str_text%2C%20%22%20%22%2C%20%22%22)%0A%20%20%20%20%0A%20%20%20%20Cells(i%2C%202)%20%3D%20link.href%0A%20%20%20%20DoEvents%0A%20%20%20%20%0A%20%20%20%20Next%0A%20%20%20%20ie.Quit%0ASet%20ie%20%3D%20Nothing%0A%0ADebug.Print%20%22done%22%20%26amp%3B%20%22Time%20taken%20%3A%20%22%20%26amp%3B%20Format(Now()%20-%20t%2C%20%22hh%3Amm%3Ass%22)%0AMsgBox%20%22Ellapsed%20Time%20-%20%22%20%26amp%3B%20Format(Now()%20-%20t%2C%20%22hh%3Amm%3Ass%22)%0A%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2693298%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2694250%22%20slang%3D%22en-US%22%3ERE%3A%20Code%20Works%20on%20Excel%202016%20but%20not%20works%20for%202010%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2694250%22%20slang%3D%22en-US%22%3Ecan%20you%20post%20the%20error%20message%3F%20Did%20you%20downgrade%20the%20reference%20of%20the%20Internet%20Explorer%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2694776%22%20slang%3D%22en-US%22%3ERE%3A%20Code%20Works%20on%20Excel%202016%20but%20not%20works%20for%202010%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2694776%22%20slang%3D%22en-US%22%3Eon%20Excel%202010%20an%20error%20appear%20that%20is%20%22run%20time%20error%2013%20type%20mismatch%22%20onthe%20line%20%22Set%20doc%20%3D%20ie.document%22%3C%2FLINGO-BODY%3E
Occasional 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?