We help IT Professionals succeed at work.
Get Started

Converting csv file to xls

davidam asked
Last Modified: 2012-05-11
We are using the following code to convert csv files to xls files
The problem is that sometimes the coversion fails to separate the data into individual cells and instead, puts all of the data into cell A1 of the newly created xls file...can we put something into line 5, the 'SaveAs' line,  to ensure that this does not happen?  (It should not matter but,  note that the new files are being created in Excel 2003, but the csv files may have been created with vba in either 03 or 07)
Thank you
Public Sub Convert_File(strCSVFile)
	xlApp.DisplayAlerts = False
	Set oCSVToConvert = xlApp.Workbooks.Open(strCSVFile, False, False)
	strConvertedName = Left(strCSVFile, Len(strCSVFile) - 4) & ".xls"
	oCSVToConvert.SaveAs strConvertedName, xlNormal
	oCSVToConvert.Close True
	xlApp.DisplayAlerts = True
	WScript.Sleep 1000
	objFSO.DeleteFile strCSVFile, True
End Sub

Open in new window

Watch Question
Most Valuable Expert 2012
Top Expert 2014
This problem has been solved!
Unlock 1 Answer and 20 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE