J
jennifer1970
I've got a CSV file to which I need to add a header line. I wrote a
little VB Script to do this. Once I ran it the size of the file
literally doubled. The header line is there now, however. When I open
the file in Excel, however, all the text in each line opens in one
cell. It's quite annoying. Has anyone seen this before? Okay, maybe
not the exact problem, but maybe where Excel won't open a CSV
correctly? I'm thinking there must be some odd character or something
in it that causes this, but the file "looks" normal.
Thanks for any suggestions,
Jennifer
Just in case anyone is interested, this is the script does:
Dim DtlHdrDim FilePath
Dim DtlName
Dim FSO, Fil, TempFile, TempName
Dim sLine
Const ForReading = 1, ForWriting = 2, ForAppending = 8
FilePath = "\\hqimpact\mktdata\Extract\"
DtlName = FilePath & "SalesDtl.csv"
TempName = FilePath & "Temp.csv"
Set FSO = CreateObject("scripting.filesystemobject")
DtlHdr =
"parSalesHdrID,parSalesDetailID,Before,Quantity,After,Promo,PromoBefore"
& _
"ItemPrice,PromoAfter,POSItem,UnitNumber,Depleted"
Set Fil = FSO.OpenTextFile(DtlName, ForReading, False)
sLine = Fil.ReadLine
If sLine <> DtlHdr Then
Set TempFile = FSO.CreateTextFile(TempName,ForWriting, True)
TempFile.WriteLine DtlHdr
Do Until Fil.AtEndOfStream
sLine = Fil.ReadLine
TempFile.WriteLine sLine
Loop
Fil.Close
FSO.CopyFile TempName, DtlName, True
TempFile.Close
FSO.DeleteFile TempName
End If
Set Fil = Nothing
Set FSO = Nothing
little VB Script to do this. Once I ran it the size of the file
literally doubled. The header line is there now, however. When I open
the file in Excel, however, all the text in each line opens in one
cell. It's quite annoying. Has anyone seen this before? Okay, maybe
not the exact problem, but maybe where Excel won't open a CSV
correctly? I'm thinking there must be some odd character or something
in it that causes this, but the file "looks" normal.
Thanks for any suggestions,
Jennifer
Just in case anyone is interested, this is the script does:
Dim DtlHdrDim FilePath
Dim DtlName
Dim FSO, Fil, TempFile, TempName
Dim sLine
Const ForReading = 1, ForWriting = 2, ForAppending = 8
FilePath = "\\hqimpact\mktdata\Extract\"
DtlName = FilePath & "SalesDtl.csv"
TempName = FilePath & "Temp.csv"
Set FSO = CreateObject("scripting.filesystemobject")
DtlHdr =
"parSalesHdrID,parSalesDetailID,Before,Quantity,After,Promo,PromoBefore"
& _
"ItemPrice,PromoAfter,POSItem,UnitNumber,Depleted"
Set Fil = FSO.OpenTextFile(DtlName, ForReading, False)
sLine = Fil.ReadLine
If sLine <> DtlHdr Then
Set TempFile = FSO.CreateTextFile(TempName,ForWriting, True)
TempFile.WriteLine DtlHdr
Do Until Fil.AtEndOfStream
sLine = Fil.ReadLine
TempFile.WriteLine sLine
Loop
Fil.Close
FSO.CopyFile TempName, DtlName, True
TempFile.Close
FSO.DeleteFile TempName
End If
Set Fil = Nothing
Set FSO = Nothing