I use this code to write to a txt file:
Dim rCell As Range
Dim rRow As Range
Dim sOutput As String
Dim sFname As String, lFnum As Long
'Open a text file to write
sFname = "\\SERVER\Company\FÖRETAGEN\RTFL Care AB\Tidrapporter\" + Range("e3").Value + ".txt"
lFnum = FreeFile
Open sFname For Output As lFnum
'Loop through the rows'
For Each rRow In ActiveSheet.UsedRange.Rows
'Loop through the cells in the rows'
For Each rCell In rRow.Cells
sOutput = sOutput & rCell.Value & ";"
Next rCell
'remove the last comma'
sOutput = Left(sOutput, Len(sOutput) - 1)
'write to the file and reinitialize the variables'
Print #lFnum, sOutput
sOutput = ""
Next rRow
Close lFnum
It works excellent, but file looks like this:
[TidTr]AnstId;Datum;ProdId;Beskr;KundId;Tid;Pt;Pris
[TidTr];;;;;;;
1;2012-01-01;11;OB Vardag;XX100;4;XX100;267
and I don't want the semicolons in line 2. The file is used for loading into an Access data base [TidTr] and Access doesn't understand in which database to load if the semicolons are there.
How do I get rid of them?
Dim rCell As Range
Dim rRow As Range
Dim sOutput As String
Dim sFname As String, lFnum As Long
'Open a text file to write
sFname = "\\SERVER\Company\FÖRETAGEN\RTFL Care AB\Tidrapporter\" + Range("e3").Value + ".txt"
lFnum = FreeFile
Open sFname For Output As lFnum
'Loop through the rows'
For Each rRow In ActiveSheet.UsedRange.Rows
'Loop through the cells in the rows'
For Each rCell In rRow.Cells
sOutput = sOutput & rCell.Value & ";"
Next rCell
'remove the last comma'
sOutput = Left(sOutput, Len(sOutput) - 1)
'write to the file and reinitialize the variables'
Print #lFnum, sOutput
sOutput = ""
Next rRow
Close lFnum
It works excellent, but file looks like this:
[TidTr]AnstId;Datum;ProdId;Beskr;KundId;Tid;Pt;Pris
[TidTr];;;;;;;
1;2012-01-01;11;OB Vardag;XX100;4;XX100;267
and I don't want the semicolons in line 2. The file is used for loading into an Access data base [TidTr] and Access doesn't understand in which database to load if the semicolons are there.
How do I get rid of them?