I am about to receive hundreds of Excel spreadsheets, of which one of the five columns is a time in the format hh:mm
The format of this source file is fixed and can not be changed.
I need to open each of the spreadsheets and save as a csv file. If I do this manually, I experience no problems at all - the resulting .csv file can be viewed in notepad with no anomalies.
However, on using a simple macro to do this, I find that when I view the resulting .csv in Notepad, all the leading zeroes are missed from the time data - i.e. 09:45 becomes 9:45. (The macro is reproduced below).
I need to retain the time in the hh:mm format with the leading zero. Any manipulation of the time field results in it being converted to a number (e.g. 09:45 becomes 0.40625).
I don't particularly want to open each of the files I receive (or convert) as there are likely to be hundreds of them.
Any ideas how to retain the original formatting?
Thanks,
David.
Dim File_Names As Variant
Dim File_count As Integer
Dim Active_File_Name As String
Dim Counter As Integer
Dim File_Save_Name As Variant
File_Names = Application.GetOpenFilename(, , , , True)
Application.ScreenUpdating = False
Application.DisplayAlerts = False
File_count = UBound(File_Names)
Counter = 1
Do Until Counter > File_count
Active_File_Name = File_Names(Counter)
Workbooks.Open Filename:=Active_File_Name
Active_File_Name = ActiveWorkbook.Name
File_Save_Name = InStr(1, Active_File_Name, ".xls", 1) - 1
File_Save_Name = Mid(Active_File_Name, 1, File_Save_Name) & ".csv"
ActiveWorkbook.SaveAs Filename:=File_Save_Name, FileFormat:= _
xlCSV
ActiveWindow.Close
Counter = Counter + 1
Loop
The format of this source file is fixed and can not be changed.
I need to open each of the spreadsheets and save as a csv file. If I do this manually, I experience no problems at all - the resulting .csv file can be viewed in notepad with no anomalies.
However, on using a simple macro to do this, I find that when I view the resulting .csv in Notepad, all the leading zeroes are missed from the time data - i.e. 09:45 becomes 9:45. (The macro is reproduced below).
I need to retain the time in the hh:mm format with the leading zero. Any manipulation of the time field results in it being converted to a number (e.g. 09:45 becomes 0.40625).
I don't particularly want to open each of the files I receive (or convert) as there are likely to be hundreds of them.
Any ideas how to retain the original formatting?
Thanks,
David.
Dim File_Names As Variant
Dim File_count As Integer
Dim Active_File_Name As String
Dim Counter As Integer
Dim File_Save_Name As Variant
File_Names = Application.GetOpenFilename(, , , , True)
Application.ScreenUpdating = False
Application.DisplayAlerts = False
File_count = UBound(File_Names)
Counter = 1
Do Until Counter > File_count
Active_File_Name = File_Names(Counter)
Workbooks.Open Filename:=Active_File_Name
Active_File_Name = ActiveWorkbook.Name
File_Save_Name = InStr(1, Active_File_Name, ".xls", 1) - 1
File_Save_Name = Mid(Active_File_Name, 1, File_Save_Name) & ".csv"
ActiveWorkbook.SaveAs Filename:=File_Save_Name, FileFormat:= _
xlCSV
ActiveWindow.Close
Counter = Counter + 1
Loop