Skip to content Skip to sidebar Skip to footer

Write And Save Html In Excel With Vba

looking for help as I have not found anything on this specific topic yet. Goal: I would like to write HTML style directly in Excel, press a button and have the generated html file

Solution 1:

Try this code

Sub Test()
Dim a           As Variant

a = Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row).Value

a = Convert2DArrayTo1DArray(a)
ArrayToTextFile a, ThisWorkbook.Path & "\Sample.html"
End Sub

Function Convert2DArrayTo1DArray(arr As Variant)
Dim b()         As Variant
Dim s           As String
Dim i           As Long

ReDim b(1 To UBound(arr, 1))

For i = 1 To UBound(arr, 1)
    b(i) = arr(i, 1)
Next i

Convert2DArrayTo1DArray = b
End Function

Function ArrayToTextFile(a As Variant, strPath As String)
Dim fso         As Object
Dim fn          As Object
Dim i           As Long

Set fso = CreateObject("Scripting.FileSystemObject")
Set fn = fso.OpenTextFile(strPath, 2, True)

For i = LBound(a) To UBound(a)
    fn.writeline a(i)
Next i

fn.Close
End Function

Post a Comment for "Write And Save Html In Excel With Vba"