mcrmg
asked on
batch CSV to Excel
Hi,
Is there a automated way to convert files in a folder from CSV to Excel? thanks
Is there a automated way to convert files in a folder from CSV to Excel? thanks
ASKER
They need to be modified.. It gas "|" as delimiter...thx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Here is a VBS script approach that will get it done. It assumes you have Excel installed on the computer you run this on though, no way around that. Save this as a VBS file, and then run like this, passing it the path to the folder with the CSV files in it to process. For each one the script will create an XLS version in the same folder. Sample command line:
cscript EE28703584.vbs C:\Files
cscript EE28703584.vbs C:\Files
'Constants
Const cExcel8 = 56
strExcel = "xls"
strCSV = "csv"
' Set up filesystem object for usage
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Get folder name to process off the command line, make sure it's valid
If (WScript.Arguments.Count > 0) Then
strFolder = Wscript.Arguments(0)
If Not objFSO.FolderExists(strFolder) Then
WScript.StdErr.WriteLine "Specified folder does not exist."
WScript.Quit
End If
Else
WScript.StdErr.WriteLine "No folder name specified to process."
WScript.Quit
End If
' Access the folder to process
Set objFolder = objFSO.GetFolder(strFolder)
' Load Excel for conversions
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = False
objExcel.DisplayAlerts = False
' Process files
For Each objFile In objFolder.Files
strPath = objFile.Path
' Only convert CSV files
If LCase(objFSO.GetExtensionName(strPath)) = LCase(strCSV) Then
' Load into Excel and save as native Excel file
Set objWorkbook = objExcel.Workbooks.Open(strPath, False, True)
objWorkbook.SaveAs Replace(strPath, strCSV, strExcel), cExcel8
objWorkbook.Close False
Set objWorkbook = Nothing
End If
Next
'Wrap up
objExcel.Quit
Set objExcel = Nothing
Set objFSO = Nothing
~bp
ASKER
Hi, bill,
Thanks for the script, but it looks like it does not modify the delimiter, or maybe I am not using it correctly. Thx
Thanks for the script, but it looks like it does not modify the delimiter, or maybe I am not using it correctly. Thx
ren *.csh *.xls