简体   繁体   中英

Getting error 800a03ec while opening an Excel file

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

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM