I have a table inside a worksheet. I used the following found here
Sub saveTableToCSV()
Dim tbl As ListObject
Dim csvFilePath As String
Dim fNum As Integer
Dim tblArr
Dim rowArr
Dim csvVal
Set tbl = Worksheets("EXPORT").ListObjects("TableName")
csvFilePath = "C:\CSVFile.csv"
tblArr = tbl.DataBodyRange.Value
fNum = FreeFile()
Open csvFilePath For Output As #fNum
For i = 1 To UBound(tblArr)
rowArr = Application.Index(tblArr, i, 0)
csvVal = VBA.Join(rowArr, ",")
Print #1, csvVal
Next
Close #fNum
Set tblArr = Nothing
Set rowArr = Nothing
Set csvVal = Nothing
End Sub
How to include the table header in the csv? My thought is to do the following
tblArr2 = tbl.HeaderRowRange.Value
But how I will join the tables?
Additionally, how to include UTF-8 support to the saved CSV?