Convert HTML-table to Excel using VBA

后端 未结 9 2113
难免孤独
难免孤独 2021-02-05 02:51

Convert HTML-table to Excel

The code below fetches the HTML-table at https://rasmusrhl.github.io/stuff, and converts it to Excel-format.

The pr

9条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-05 03:07

    With the url https://rasmusrhl.github.io/stuff, it's by luck that Excel can simply just open it directly and save as .xlsx (how come no one try this before the tedious process). If direct open fails, all other methods here are great option!

    Option Explicit
    
    Sub OpenWebFile()
        Const URL As String = "https://rasmusrhl.github.io/stuff"
        Dim oWB As Workbook
        On Error Resume Next
        Set oWB = Workbooks.Open(Filename:=URL, ReadOnly:=True)
        If oWB Is Nothing Then
            MsgBox "Cannot open the url " & URL, vbExclamation + vbOKOnly, "ERR " & Err.Number & ":" & Err.Description
            Err.Clear
        Else
            ' Change to your desired path and filename
            oWB.SaveAs Filename:="C:\Test\stuff.xlsx", FileFormat:=xlOpenXMLWorkbook
            Set oWB = Nothing
        End If
    End Sub
    

提交回复
热议问题