0

I am encountering an

Object doesn't support this property or method

Runtime error in excel vba.

Note : The code works fine in my laptop.This error happened when I migrated the code to my desktop pc.

Below is the UPDATED code.

Dim ie As InternetExplorer

Dim htmldoc As MSHTML.IHTMLDocument

Dim ro1 As MSHTML.IHTMLElementCollection

Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = False

ie.navigate "url"

Set htmldoc = ie.document

Set ro1 = htmldoc.getElementById("table id").getElementsByTagName("tr")

ThisWorkbook.Sheets(1).Cells(k, j) = rows(k).Children(0).textContent 

ro1(k).Children(0).textContent is the error part.

I have checked Tools->References. Microsoft Internet Controls and Microsoft HTML Object Library has been checked.

Can anyone please guide me for this ?

14
  • Start by adding a line Option Explicit at the top of your module, and then Debug->Compile to identify variables and objects that aren't properly declared or are being misused, Keep compiling until no more warnings. Commented Dec 28, 2017 at 10:58
  • What is rows(k).Children(0)? Run in Immediate Window: ?TypeName(rows(k).Children(0)) Commented Dec 28, 2017 at 11:00
  • 1
    What about rows(k).Children(0).InnerText? Commented Dec 28, 2017 at 11:06
  • 1
    @user3126632 I only replaced rows(k).Children(0).textContent with rows(k).Children(0).InnerText. Did you try that? Commented Dec 28, 2017 at 11:30
  • 1
    @sktneer That's the answer.Replaced textContent with InnerText .Please post as answer with needed explanatiion Commented Dec 28, 2017 at 11:51

2 Answers 2

1

Try using InnerText instead of textContent and see if that works for you.

ThisWorkbook.Sheets(1).Cells(k, j) = rows(k).Children(0).InnerText
Sign up to request clarification or add additional context in comments.

Comments

0

Start by adding a line Option Explicit at the top of your module, and then Debug->Compile to identify variables and objects that aren't properly declared or are being misused, Keep compiling until no more warnings.

Also, don't use the word ROWS as an object name. Rows already means something in Excel & VBA.

Here is a list of reserved words that should be avoided. (I realize it's labelled Access 2007 but the list is very similar, and it's surprisingly difficult to find an recent 'official' list for Excel VBA.)

5 Comments

I replaced rows with ro1.But that is still not serving the purpose. Note : Code runs fine on my laptop.
you replaced all occurrences iin the project? Aldo did you add Option Explicit to all modules in the project?
ok so did you declare htmldoc ? Or is that declared elsewhere in code that wasn't shared?
Dim htmldoc As MSHTML.IHTMLDocument is declared in the code.
okay, not in the code you shared. Also I don't see a target URL being assigned to an object. What page is this trying to open? Also what is the value of k and j? This would be much easier with all of the related information.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.