Results 1 to 40 of 43

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

Hybrid View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2009
    Posts
    295

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

    I just need the header from the first file of html folder, it can be ignored from rest all files since we will append data from each file one below another. Below is the snapshot highlighting the header row.

    Also I added the reference to Microsoft Forms 2.0 Object Library, it wasn't appearing in the references in excel 2010 but i used the browse button and selected it from C:\WINDOWS\system32\FM20.DLL and then it started appearing in the references but when I run the code nothing happens. It doesn't show any error as well.


    Code:
    Sub GetHTMLFiles ()
    Dim doc As MSHTML.HTMLDocument, d As DataObject, htm As String
        Set d = New DataObject
        Set doc = CreateObject("htmlfile")
        fpath = "C:\users\abhy\desktop\htmldatafiles\"
        fpath = "C:\users\abhy\Appdata\Local\Temp"
        f = Dir(fpath & "*.htm")
        Do While f <> ""
            Open fpath & f For Input As 1
            htm = Input(LOF(1), #1)
            Close 1
            doc.body.innerHTML = htm
            Set t = doc.getElementsByTagName("table")(0)
            d.Clear
            d.settext t.innerText
            d.PutInClipboard
            rw = Cells(Rows.Count, 1).End(xlUp).Row + 1
            If rw = 2 Then rw = 1
            Cells(rw, 1).PasteSpecial
            If rw = 1 Then   'fix headers
    
                Else  ' delete headers
                hrows = 12    ' may need adjustment
                Cells(rw, 1).Resize(hrows).EntireRow.Delete
            End If
            f = Dir
        Loop
    End Sub
    Attached Images Attached Images  
    Last edited by abhay_547; Feb 11th, 2018 at 05:00 AM.

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