2

I have written following code to convert XLSX file to CSV format:

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

It was working fine when I was giving server path for XLSX file. But, when I am giving local machine path, it is giving me following error:

File could not be found. Check the spelling of the file name, and verify that file location is correct. If you are trying to open the file from list of most recently used files, make sure that file has not been renamed, moved or deleted
code: 800A03EC
Source: Microsoft Office Excel

3
  • Please take a look at the preview before you submit a question or an answer. May 6, 2013 at 7:46
  • What do you call "server path" and "local machine path"? Please show us your command line. May 6, 2013 at 11:55
  • I have exactly the same problem with MS Office Professional Plus 2010 Jul 4, 2013 at 9:23

3 Answers 3

5

In case anyone with a similar problem finds this, the error code seems to be a general Excel error which means that it could not open the file.

In my case I tried opening the same file manually and found that Excel wanted to repair a corrupted file. I had been allowed to save it with incorrect validations, but it wouldn't open programmatically. Opening it by hand meant that it could show me a dialog asking whether I wanted to fix it or not.

1
  • Thanks, in my case it was invalid characters in a file name.
    – AjV Jsy
    Jun 5, 2018 at 12:16
4

If you are still getting this error, I would do a simple echo on both your arguments to make sure they are doing exactly what they should be doing

wscript.echo "Arg(0): " & WScript.Arguments.Item(0) & " Arg(1): " & WScript.Arguments.Item(1)

Also if you are using cscript.exe to run it, it will by default be looking for the files in c:\windows\system32\ directory

1
  • And how to modify this default location? also when I copied the file to this location I got exactly the same error:D Jul 4, 2013 at 9:24
0

In my case the corresponding message is "Unable to set the PaperSize property of the PageSetup class". That occurs when the standard printer is not capable of the page format of the Excel workbook/sheet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.