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

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,224,820
Messages
6,181,155
Members
453,021
Latest member
Justyna P

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