nested for loop with item

romanemul

New Member
Joined
Jul 22, 2016
Messages
35
Hello members,

Im working with the for loop to iterate through webpage node collection.

Data i want to pull out are everytime nested in node number 2.

Code:
ChildNodes.Item(2).innerText

But my code breaks telling me Invalid argument error. My thoughts are probably because double Item property.
Also childNodes property is always corrected by engine to ChildNodes with upper "C" at the beggining of code.

I tried fixing the code with 'With' statement to correct namespace but i dont know how to.


full code:

Code:
Sub sendToAccess(ByVal elements As MSHTML.IHTMLElementCollection)
   
    Dim dbConn As ADODB.Connection
    Dim dbRs As ADODB.Recordset
    Dim dbConnString As String
    
    Dim wb As Workbook
    Dim ws As Worksheet
    Dim i As Double
    
    dbConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\mydb.accdb;"
    
    Set wb = Workbooks("mysheet.xlsm")
    Set ws = wb.Worksheets("Sheet1")

'for loop is not finished

For i = 1 To elements.Length
     'With elements
        ws.Range("A1").Value = elements.Item(i).ChildNodes.Item(2).innerText    'problem line
        ActiveCell.Cells.Columns.AutoFit
     'End With
Next i

'... further code...

End Sub

Thanks for your help.

R.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,223,886
Messages
6,175,193
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top