VBA Web Automation, Table inside a Table

mrshl9898

Well-known Member
Joined
Feb 6, 2012
Messages
1,951
Hi,

I'm using the following to look for a table. I have seen all the tables it loops through and none are the one I am after.

Looking at the HTML the Table I need is inside tblRates.

How do I loop through Tables within that Table?



*BTW this is Intranet stuff so won't work for testing... Though here is a link to the code

https://ibb.co/n7hB76



Code:
Sub runreports()

    Dim IE As New SHDocVw.InternetExplorer
    Dim HTMLdoc As MSHTml.HTMLDocument
    Dim objShellWindows As New SHDocVw.ShellWindows
    
    schedID = Sheets("Schedules").Range("A1").Value
     
    Set IE = GetObject("new:{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}")
    With IE
        .Visible = True
        .Navigate "http://maintrakautest/Domestic/"
    While .Busy Or .ReadyState <> 4: DoEvents: Wend
    End With


    With IE
        .Visible = True
        .Navigate "http://maintrakau/OnForward/Business/ScheduleFCLNZ1.asp?sid=" & schedID


    While .Busy Or .ReadyState <> 4: DoEvents: Wend
    
    Set Schedpage = IE.Document.getElementById("page2")
    Schedpage.Click
         
    Set HTMLdoc = IE.Document
     
    ProcessHTMLPage HTMLdoc
    
    End With
    
    IE.Quit
    
    
End Sub


Sub ProcessHTMLPage(HTMLPage As MSHTml.HTMLDocument)


    Dim HTMLTable As MSHTml.IHTMLElement
    Dim HTMLTable1 As MSHTml.IHTMLElement
    Dim HTMLTables As MSHTml.IHTMLElementCollection
    Dim HTMLTables1 As MSHTml.IHTMLElementCollection
    Dim HTMLRow As MSHTml.IHTMLElement
    Dim HTMLCell As MSHTml.IHTMLElement
    Dim class As MSHTml.IHTMLAttributeCollection
    Dim Templatetext As String
    Dim NewText As String
        
    Set HTMLTables = HTMLPage.getElementsByTagName("table")
    
    For Each HTMLTable In HTMLTables
    
        If HTMLTable.ID = "tblRates" Then
    
        MsgBox "success"


        End If
    
    Next HTMLTable
    
    'tblRates
    'tblAdditionalCharges


End Sub
 
Last edited by a moderator:

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Looking at the HTML the Table I need is inside tblRates.

How do I loop through Tables within that Table?
Maybe:
Code:
Dim RatesTable As HTMLTable
Dim Table As HTMLTable
Set RatesTable = HTMLPage.GetElementById("tblRates")
For Each Table In RatesTable.GetElementsByTagName("TABLE")
    MsgBox Table.InnerText
Next
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

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