hi,
I'm trying to create a csv file.
Is there any way to keep the same figures format as in the initial excel file when printing the csv or shall we define the format of every column in the loop(and how)?
Actually in the excel file, some columns contain figures that must be formatted as 0.00000(5decimals mandatory even if zero). But when printing the csv with this loop, the useless ending 0 are deleted...
Below is the current code :
thanks
I'm trying to create a csv file.
Is there any way to keep the same figures format as in the initial excel file when printing the csv or shall we define the format of every column in the loop(and how)?
Actually in the excel file, some columns contain figures that must be formatted as 0.00000(5decimals mandatory even if zero). But when printing the csv with this loop, the useless ending 0 are deleted...
Below is the current code :
Code:
Sub Export_As_Semicolon_delimited() Dim objSaveBox As FileDialog Dim MYFILE As String Dim r As Long, c As Long Const DELIMITER = ";" Sheets("INF").Select ' ChDrive = "C:\" ' set default save drive ' ChDir = "C:\Temp" ' set default save directory (can't change default drive with just this) Set objSaveBox = Application.FileDialog(msoFileDialogSaveAs) With objSaveBox .InitialFileName = Range("A3") & "_INF_" & Range("C3") & ".csv" '.FilterIndex = 15 If .Show = -1 Then MYFILE = .SelectedItems.Item(1) Else Exit Sub End If End With 'Write cells from A2 to (last row, last column) to a Semicolon delimted text file FileNum = FreeFile Open MYFILE For Output As #FileNum For r = 2 To Range("A2").End(xlDown).Row For c = 1 To Range("A2").End(xlToRight).Column Print #FileNum, Cells(r, c).Value & DELIMITER; Next c Print #FileNum, Next r Close #FileNum MsgBox "File saved as a Semicolon delimited text file." & _ vbLf & vbLf & MYFILE, , "Save Complete" End Sub</pre>
thanks