Table Manipulation – Set ListObject Headers
Sets the header row of an Excel.ListObject using values from a CSV-formatted string.
The function splits the HeaderCSV string and assigns each value to the corresponding header cell in the list object’s header row. If the list object is Nothing , the function exits without changes.
VB
Public Sub xlSetListObjectHeaders(ListObject As Excel.ListObject,
HeaderCSV As String,
Optional Separator As String = ";")
If ListObject Is Nothing Then Return
Dim arHeader As String() = Split(HeaderCSV, Separator)
Dim iColIndex As Integer
For Each szHeader As String In arHeader
iColIndex += 1
ListObject.HeaderRowRange.Cells(1, iColIndex).Value = szHeader
Next
End Sub