Consulting

Results 1 to 3 of 3

Thread: Import HTML Data into excel

  1. #1

    Import HTML Data into excel

    I got the below macro from a old thread. I have the lines on the html pages saved on my 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.


    'Requires references to Microsoft Internet Controls and Microsoft HTML Object Library 
    Sub Extract_TD_text() 
         
        Dim URL As String 
        Dim IE As InternetExplorer 
        Dim HTMLdoc As HTMLDocument 
        Dim TDelements As IHTMLElementCollection 
        Dim TDelement As HTMLTableCell 
        Dim r As Long 
         
         'Saved from www vbaexpress com/forum/forumdisplay.php?f=17
        URL = "file://C:\VBAExpress_Excel_Forum.html" 
         
        Set IE = New InternetExplorer 
         
        With IE 
            .navigate URL 
            .Visible = True 
             
             'Wait for page to load
            While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend 
                 
                Set HTMLdoc = .document 
            End With 
             
            Set TDelements = HTMLdoc.getElementsByTagName("TD") 
             
            Sheet1.Cells.ClearContents 
             
            r = 0 
            For Each TDelement In TDelements 
                 'Look for required TD elements - this check is specific to VBA Express forum - modify as required
                If TDelement.className = "alt2" And TDelement.Align = "center" Then 
                    Sheet1.Range("A1").Offset(r, 0).Value = TDelement.innerText 
                    r = r + 1 
                End If 
            Next 
             
        End Sub

    attached is the html image.
    Attached Images Attached Images

  2. #2

  3. #3
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    But the code is different!!
    Semper in excretia sumus; solum profundum variat.

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
  •