loosing leading zeros in excel/csv import
Posted on 2007-03-19
I have another one of those leading zero problems with excel and csv files. I currently have a script that runs and pulls in a csv file, cuts half the fields out, shottens one of the field lengths and then saves the file again. It runs automatically on an entire folder using a wildcard for the filename.
Today we had a new problem in that one of the fields started with a zero and excel removed it, which caused major plant faliure because the resulting files are combined and then read into a plc for build info.
Anyone know how to read in the csv and keep the zero?
this is the script currently used:
rivate Sub Workbook_Open()
Application.Visible = True
Dim FileName As String
Const Folder = "C:\process"
FileName = Dir(Folder & "\*.txt")
Do While FileName <> ""
Application.Workbooks.Open Folder & "\" & FileName
ActiveCell.FormulaR1C1 = "=MID(RC[-1],1,50)"
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
Application.CutCopyMode = False
FileName = Dir
any help appreciated.