Hi everybody,
Below is the VBA code i use behind a button to export the current sheet to a semicolon ( separated txt file. The code works fine as it is, but it also exports the headers in the excel sheet, and I don't want this. I'm new to VBA and I'm quite happy I got the below code to work but it would be better if the header would be skipped. I have tried different things, but can't get it to work. can you please help me with this? I need to use the below code to make sure the separation is always done by semicolon (this sheet is used on multiple computers with different local settings). I cannot use the local separator as it will be a semicolon for me, but a comma for a colleague.
Thank you in advance.
Private Sub CommandButton1_Click()
Dim rCell As Range
Dim rRow As Range
Dim sOutput As String
Dim sFname As String, lFnum As Long
sFname = ThisWorkbook.Path & "\MyFile6.txt"
lFnum = xlCSV
Open sFname For Output As lFnum
For Each rRow In ActiveSheet.UsedRange.Rows
For Each rCell In rRow.Cells
sOutput = sOutput & rCell.Text & ";"
Next rCell
sOutput = Left(sOutput, Len(sOutput) - 1)
Print #lFnum, sOutput
sOutput = ""
Next rRow
End Sub
Below is the VBA code i use behind a button to export the current sheet to a semicolon ( separated txt file. The code works fine as it is, but it also exports the headers in the excel sheet, and I don't want this. I'm new to VBA and I'm quite happy I got the below code to work but it would be better if the header would be skipped. I have tried different things, but can't get it to work. can you please help me with this? I need to use the below code to make sure the separation is always done by semicolon (this sheet is used on multiple computers with different local settings). I cannot use the local separator as it will be a semicolon for me, but a comma for a colleague.
Thank you in advance.
Private Sub CommandButton1_Click()
Dim rCell As Range
Dim rRow As Range
Dim sOutput As String
Dim sFname As String, lFnum As Long
sFname = ThisWorkbook.Path & "\MyFile6.txt"
lFnum = xlCSV
Open sFname For Output As lFnum
For Each rRow In ActiveSheet.UsedRange.Rows
For Each rCell In rRow.Cells
sOutput = sOutput & rCell.Text & ";"
Next rCell
sOutput = Left(sOutput, Len(sOutput) - 1)
Print #lFnum, sOutput
sOutput = ""
Next rRow
End Sub
Last edited: