I'm looking for a way to batch-convert a series of .csv files to .xlsx using the command line.
I have tried a bunch of different VBScripts that I found but they all seem to be converting .xlsx to .csv and not the other way around.
Here is the closest one I could find but again it's .xlsx to .csv:
if WScript.Arguments.Count < 2 Then
WScript.Echo "Error! Please specify the source path and the destination. Usage: XlsToCsv SourcePath.xls Destination.csv"
Wscript.Quit
End If
Dim oExcel
Set oExcel = CreateObject("Excel.Application")
Dim oBook
Set oBook = oExcel.Workbooks.Open(Wscript.Arguments.Item(0))
oBook.SaveAs WScript.Arguments.Item(1), 6
oBook.Close False
oExcel.Quit
WScript.Echo "Done"
Any ideas?
解决方案
only pre-requisite is that the ".csv" must be lower case in the filename:
Dim file, WB
With CreateObject("Excel.Application")
On Error Resume Next
For Each file In WScript.Arguments
Set WB = .Workbooks.Open(file)
WB.SaveAs Replace(WB.FullName, ".csv", ".xlsx"), 51
WB.Close False
Next
.Quit
End With
WScript.Echo "Done!"