Search code examples
htmlexcelvbagetelementbyid

getElementById innerHTML Runtine error 91


I am trying to extract the text from an html line (shown below) using excel vba.

<textarea class="textareaMod task-title" id="task-description">software Developemnt</textarea>

I am getting Runtime error 91 every time the code runs. Below is a part of my code. Any help to resolve this is much appreciated.

Dim ie As InternetExplorer
Dim html As HTMLDocument
Set ie = New InternetExplorer
ie.Visible = True
ie.navigate URLstr
Do While ie.READYSTATE <> READYSTATE_COMPLETE
Application.StatusBar = "Trying to connect to the source..."
DoEvents
Loop

Set html = ie.document
Set ie = Nothing
Application.StatusBar = ""
Dim title, header As String

title = html.getElementById("task-description").innerHTML
Activesheet.Range("B2").Value = title

Solution

  • Thanks SIM and Cindy ! This worked for me:

    Dim Title As Object
    Dim TitleTxt As String 
    Set Title = html.getElementById("task-description") 
    TitleTxt = Title.innerText 
    Activesheet.Range("B2").Value = Title