Import Value in Excel from Internet Explorer table

Image: Kindly read the image from top left to right while coming down

I’m trying to import data (a cell value) from IE to Excel given there is a lag to generate the table.

Here’s what I’m trying to do via excel:

  1. Go to FOIS site. (Done)
  2. Input “Description” from excel. (Done)
  3. Input “Unit Details” from excel. (Done)
  4. Get cell value: [Freight_Rate][Train_Load]. (Not Done)
  5. Given 20X10 table with headers [Station_From][Station_To], fill it with respective Step 4 value. (Not Done)

Despite a lot of tries, for some the cell value fails to populate into excel.

Any help would be great. Thank you.

Here’s the code that I wrote:

Following is for the first 3 steps:

Sub ChromAuto()

    Dim IE As Object
    Dim doc As HTMLDocument
    Dim table As HTMLTable
    Dim rateclass As String
    Dim fgtrate As String
    
    Set IE = CreateObject("InternetExplorer.Application")

    IE.Visible = True
    IE.navigate "https://www.fois.indianrail.gov.in/FOISWebPortal/pages/FWP_FrgtCalcNew.jsp"

    Do While IE.Busy
        Application.wait DateAdd("s", 1, Now)
    Loop

    Set doc = IE.document

    doc.getElementById("txtSttnFrom").Value = ThisWorkbook.Sheets("Data").Range("C2").Value
    doc.getElementById("txtSttnTo").Value = ThisWorkbook.Sheets("Data").Range("C3").Value
    doc.getElementById("txtWgonType").Value = ThisWorkbook.Sheets("Data").Range("C4").Value
    doc.getElementById("txtCtgy").Value = ThisWorkbook.Sheets("Data").Range("C6").Value
    doc.getElementById("txtCmdtName").Value = ThisWorkbook.Sheets("Data").Range("C7").Value

    If ThisWorkbook.Sheets("Data").Range("C5").Value = "General" Then
        doc.getElementById("selDvsn").Value = "GA"
    ElseIf ThisWorkbook.Sheets("Data").Range("C5").Value = "Low Rated (A-Division)" Then
        doc.getElementById("selDvsn").Value = "LA"
    ElseIf ThisWorkbook.Sheets("Data").Range("C5").Value = "Low Rated (B-Division)" Then
        doc.getElementById("selDvsn").Value = "LB"
    ElseIf ThisWorkbook.Sheets("Data").Range("C5").Value = "Low Rated (C-Division)" Then
        doc.getElementById("selDvsn").Value = "LC"
    ElseIf ThisWorkbook.Sheets("Data").Range("C5").Value = "Low Rated (D-Division)" Then
        doc.getElementById("selDvsn").Value = "LD"
    End If

    doc.getElementById("cmdGetInfo").Click
    
    Do While IE.Busy Or IE.readyState <> 4
        Application.wait DateAdd("s", 1, Now)
    Loop
    
    If ThisWorkbook.Sheets("Data").Range("C9").Value = "Rake" Then
        doc.getElementById("selRKPM").Value = "R"
    ElseIf ThisWorkbook.Sheets("Data").Range("C9").Value = "Mini Rake" Then
        doc.getElementById("selRKPM").Value = "M"
    ElseIf ThisWorkbook.Sheets("Data").Range("C9").Value = "Piecemeal" Then
        doc.getElementById("selRKPM").Value = "P"
    End If

    doc.getElementById("txtWgonNumb").Value = 20

    IE.Quit
    Set IE = Nothing

End Sub

Following is the try for step 4 where I’m stuck:

'Wait for the table to be available
Do While doc.getElementById("tblFrgtCalcDtls") Is Nothing
    Application.wait DateAdd("s", 1, Now)
Loop

Application.wait DateAdd("s", 3, Now)

     ' Retrieve the table
'    Set table = doc.getElementById("tblFrgtCalcDtls")
'    Set table = doc.getElementById("tblFrgtCalcDtls")
'    Set table = doc.getElementsByClassName("col col-lg-6 col-md-6 col-sm-12 col-xs-12")(0)

'Try 2
    Dim HTMLTables As MSHTML.IHTMLElementCollection
    Dim HTMLTable As MSHTML.IHTMLElement
    Dim HTMLDiv As MSHTML.IHTMLElement
    Dim TableSection As MSHTML.IHTMLElement
    
    Set HTMLDiv = doc.getElementById("dataDiv")
    Set HTMLTables = HTMLDiv.getElementsByTagName("table")
    
    For Each HTMLTable In HTMLTables
        Debug.Print HTMLTable.ID, HTMLTable.className
        
        For Each TableSection In HTMLTable.Children
            Debug.Print , TableSection.Tag
        Next TableSection
        
    Next HTMLTable
        
    
'    Debug.Print table
    
'    If Not table Is Nothing Then
        ' Extract cell values
'        rateclass = table.Rows(1).Cells(2).innerText
'        fgtrate = table.Rows(7).Cells(2).innerText
        
        ' Print the values
 '       ThisWorkbook.Sheets("Data").Range("C11").Value = rateclass
 '       ThisWorkbook.Sheets("Data").Range("C12").Value = fgtrate

'    Else
'        Debug.Print "Error: Table not found on the webpage."
'    End If
    
'    rateclass = doc.getElementById("lblAdd").innerText

New contributor

AIBot is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật