Results 1 to 40 of 43

Thread: Import data from multiple html files into one excel worksheet

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2009
    Posts
    295

    Import data from multiple html files into one excel worksheet

    I got the below macro from a old thread. I have the lines on the html page files saved on c drive, which are supposed to be in a table format but they are not and there is no separator between each column data except some undefined spaces as shown in below image, so how can i import it as a proper table .i.e. into separate columns in the excel file, also i have multiple such html files so can i import multiple files into one worksheet at one go.


    Code:
    Sub HTML_Table_To_Excel()
    
        Dim htm As Object
        Dim Tr As Object
        Dim Td As Object
        Dim Tab1 As Object
    
        'Replace the URL of the webpage that you want to download
        Web_URL = VBA.Trim(Sheets(1).Cells(1, 1))
    
        'Create HTMLFile Object
        Set HTML_Content = CreateObject("htmlfile")
    
        'Get the WebPage Content to HTMLFile Object
        With CreateObject("msxml2.xmlhttp")
            .Open "GET", Web_URL, False
            .send
            HTML_Content.body.innerHTML = .responseText
        End With
    
        Column_Num_To_Start = 1
        iRow = 2
        iCol = Column_Num_To_Start
        iTable = 10
    
        'Loop Through Each Table and Download it to Excel in Proper Format
        For Each Tab1 In HTML_Content.getElementsByTagName("table")
            With HTML_Content.getElementsByTagName("table")(iTable)
                For Each Tr In .Rows
                    For Each Td In Tr.Cells
                        Sheets(1).Cells(iRow, iCol).Select
                        Sheets(1).Cells(iRow, iCol) = Td.innerText
                        iCol = iCol + 1
                    Next Td
                    iCol = Column_Num_To_Start
                    iRow = iRow + 1
                Next Tr
            End With
            iTable = iTable + 1
            iCol = Column_Num_To_Start
            iRow = iRow + 1
        Next Tab1
    End Sub
    attached is my html file image.
    Attached Images Attached Images  

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width