Run time error on getElementsById() function in VBA script

Error:
Runtime error 438,
Object doesn't support this property or method

DoEvents
Loop Until IE.readyState = READYSTATE_COMPLETE
Dim Doc As HTMLDocument
Set Doc = IE.document
Dim topic As Variant
topic = Doc.getElementsById("description")(0).innerText

Open in new window

karthik80cAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
not too sure but you can try:

topic = Doc.getElementById("description")(0).innerText

?
ste5anSenior DeveloperCommented:
Please post a complete and concise example.

What does Doc.getElementsById("description") return, if it returns anything at all?
karthik80cAuthor Commented:
Need to scrap the text in h3 tag

<div id="description">
<h3>The Key Industrial Park - 18 Prime Lots with EastLink Exposure</h3> 
<p class="body">Frasers Property is pleased to offer 18 allotments from 1,093m² to 3.681ha as part of their stage 4 &amp; 5 release.<br><br>• 31 Allotments already sold<br><br>• Superb opportunity for owner-occupiers and developers<br><br>• Allotments with EastLink access like this are increasingly difficult to find<br><br>• Join other big names – Miele, BIC, TriMas, Tyres4U, Early Settler, Sealy, Victoria Station, Rinnai<br><br>Contact the appointed agents for a copy of the Information Memorandum and Plan of Subdivision.</p></div>

Open in new window

I cant scrap it with the <h3> tag name, because there are 8 <h3> tags in a page. so tried to get the text with id. But It returns "[object HTMLMetaElement]"
VB Code:
Sub PropertyURLL()
Dim IE As New InternetExplorer
IE.navigate "http://www.realcommercial.com.au/property-retail-qld-kooralbyn-501463555"
Do
DoEvents
Loop Until IE.readyState = READYSTATE_COMPLETE
Dim Doc As HTMLDocument
Set Doc = IE.document
Dim adtop As String
Dim sDD As String
sDD = Trim(Doc.getElementsByTagName("h1")(0).innerText)
Dim topic As Variant
topic = Doc.getElementById("description")
Dim status As Variant
status = Doc.getElementsByClassName("saleType")(0).innerText
Dim body As Variant
body = Doc.getElementsByClassName("body")(0).innerText
Dim price As Variant
price = Doc.getElementsByClassName("price ellipsis")(0).innerText

MsgBox topic

 Dim dtInspDate As Variant
 Dim dtInspTime As Variant
 Dim aTextTmp As Variant, aInspDate As Variant
aInspDate = Split(sDD, ", ")
dtInspDate = aInspDate(1)
dtInspDe = aInspDate(0)
Dim Poost As String
Poost = Right(sDD, 4)
Dim suburb As String
suburb = dtInspDate
Title = dtInspDe
End Sub

Open in new window

ste5anSenior DeveloperCommented:
Okay..

Step 1: Decouple your methods. Build one to retrieve the document. Handover the document to a second method to parse it.

Step 2: As a beginner use early binding. Set references to Microsoft HTML Object Library and Microsoft Internet Controls.

Step 3: Almost anything returned is an object. Thus use strict typing (no variants please).

E.g.

Option Explicit

Public Function GetHtml() As String

  GetHtml = GetHtml & "<html><body><div><h3>Not me.</h3></div>"
  GetHtml = GetHtml & "<div id=""description""><h3>The Key Industrial Park - 18 Prime Lots with EastLink Exposure</h3><p class=""body"">Frasers Property is pleased to offer 18 allotments from 1,093m² to 3.681ha as part of their stage 4 &amp; 5 release.<br><br>• 31 Allotments already sold<br><br>• Superb opportunity for owner-occupiers and developers<br><br>• Allotments with EastLink access like this are increasingly difficult to find<br><br>• Join other big names – Miele, BIC, TriMas, Tyres4U, Early Settler, Sealy, Victoria Station, Rinnai<br><br>Contact the appointed agents for a copy of the Information Memorandum and Plan of Subdivision.</p></div>"
  GetHtml = GetHtml & "</body></html>"

End Function

Public Function GetDocument() As MSHTML.HTMLDocument
' Here you can retrive your document by IE or what ever you like to test.

  Set GetDocument = New MSHTML.HTMLDocument
  GetDocument.body.innerHTML = GetHtml
  
End Function

Public Sub PropertyURLL()

  Dim Document As MSHTML.HTMLDocument
  Dim Topic As MSHTML.IHTMLElement
  
  Set Document = GetDocument
  Set Topic = Document.getElementById("description")
  
  Debug.Print Topic.innerHTML
  
  Set Topic = Nothing
  Set Document = Nothing

End Sub

Open in new window


Use this as a start to retrieve what you want.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Outlook

From novice to tech pro — start learning today.