简体   繁体   中英

Macro to import local .html file to excel

I have an Excel spreadsheet which compares data from a TXT file with a UDL file. These formats import easily into my spreadsheet.

Then I attempted to import a locally stored .html file into this spreadsheet through a macro button, I did not succeed writing my own code nor finding correct code on the internet.

What I need help with:

  1. Press button and select a locally stored .HTML file
  2. Convert it to xlsx
  3. Automatically adding the new xlsx file to a tab in the original spreadsheet.

My .HTML file converts perfectly to xlsx with the code below:

Sub Open_HTML_Save_XLSX()

Workbooks.Open Filename:="C:\Temp\Example.html"
    ActiveWorkbook.SaveAs Filename:= _
        "C:\Temp\Example.xlsx", FileFormat:= _
        xlOpenXMLWorkbook

End Sub

Thank you Alok Singh for your input. I managed to answer my question on my own, sorry for the inconvenience :). posting my answer below

Sub Button_click()
Range("A1:s1000").Clear
Dim OpenFileName As String
Dim wb As Workbook

OpenFileName = Application.GetOpenFilename("Your .HTML file ,*.html")
If OpenFileName = "False" Then Exit Sub
Set wb = Workbooks.Open(OpenFileName)

ThisWorkbook.Sheets(1).Range("a1:s1000").Value = wb.Sheets(1).Range("a1:s1000").Value


End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM