I am new to batch scripting and vbscript. What I want to do is convert .xlsx Excel files into .csv Excel files, in multiple directories (Recursively). For example:
Main directory
subdirectory1
file1.xlsx
file2.xlsx
subdirectory2
file3.xlsx
file4.xlsx
I have made this batch script:
FOR /r %%a in (*.xlsx) do (
SET filename=%%a
ExceltoCSV.vbs %filename% *.csv
)
Inside the for loop is the ExceltoCSV.vbs. I got this code from this thread Convert XLS to CSV on command line, and I have tried the top 2 answers already (Both don't require downloading anything).
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"
The error is saying that the ExceltoCSV.vbs file cannot be accessed. However, I believe the batch script is working, for example it would say:
SET filename=C:\folder\subfolder\test1.xlsx
then it calls:
ExceltoCSV.vbs C:\folder\subfolder\test1.xlsx *.csv
I am not sure what the problem is and I am currently very confused.