shankar kumar
New Member
- Joined
- Jul 6, 2011
- Messages
- 4
Hi Everyone
I am using office 2007. I am trying to convert .xls/.xlsx file to .csv file.
I am using following piece of code:
Sub ConvertXLStoCSV()
Dim strXLSFile As String
Dim strCSVFile As String
'Change Input and Output folders to relevant location
Const strInputFolder As String = "C:\Documents and Settings\shankar_kumar\Desktop\VBA\"
Const strOutputFolder As String = "C:\Documents and Settings\shankar_kumar\Desktop\VBA\"
strXLSFile = Dir(strInputFolder & "*.xls")
Do While strXLSFile <> ""
strCSVFile = Left(strXLSFile, InStrRev(strXLSFile, ".")) & "csv"
Workbooks.Open strInputFolder & strXLSFile
ActiveWorkbook.SaveAs strOutputFolder & strCSVFile, xlCSV
ActiveWorkbook.Close False
strXLSFile = Dir
Loop
End Sub
It works absolutely fine.
However, there is one BIG problem.
One of the field in excel file has values say:6879450129070244523
But this value appears as 6880000000000000000 in the resulting csv file.
Is there any way to preserve the values of excel file in csv file? If yes, please tell me how to modify my code to make sure the preservation of values takes place?
Appreciate your co-operation.
Thanks
Shankar
I am using office 2007. I am trying to convert .xls/.xlsx file to .csv file.
I am using following piece of code:
Sub ConvertXLStoCSV()
Dim strXLSFile As String
Dim strCSVFile As String
'Change Input and Output folders to relevant location
Const strInputFolder As String = "C:\Documents and Settings\shankar_kumar\Desktop\VBA\"
Const strOutputFolder As String = "C:\Documents and Settings\shankar_kumar\Desktop\VBA\"
strXLSFile = Dir(strInputFolder & "*.xls")
Do While strXLSFile <> ""
strCSVFile = Left(strXLSFile, InStrRev(strXLSFile, ".")) & "csv"
Workbooks.Open strInputFolder & strXLSFile
ActiveWorkbook.SaveAs strOutputFolder & strCSVFile, xlCSV
ActiveWorkbook.Close False
strXLSFile = Dir
Loop
End Sub
It works absolutely fine.
However, there is one BIG problem.
One of the field in excel file has values say:6879450129070244523
But this value appears as 6880000000000000000 in the resulting csv file.
Is there any way to preserve the values of excel file in csv file? If yes, please tell me how to modify my code to make sure the preservation of values takes place?
Appreciate your co-operation.
Thanks
Shankar