简体   繁体   English

打开Excel文件时出现错误800a03ec

[英]Getting error 800a03ec while opening an Excel file

I have written following code to convert XLSX file to CSV format: 我编写了以下代码将XLSX文件转换为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

It was working fine when I was giving server path for XLSX file. 当我为XLSX文件提供服务器路径时,它工作正常。 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 代码:800A03EC
Source: Microsoft Office Excel 来源: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 此外,如果您使用cscript.exe来运行它,它将默认在c:\\ windows \\ system32 \\目录中查找文件

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. 如果有任何类似问题的人发现这一点,错误代码似乎是一般的Excel错误,这意味着它无法打开该文件。

In my case I tried opening the same file manually and found that Excel wanted to repair a corrupted file. 在我的情况下,我尝试手动打开相同的文件,发现Excel想要修复损坏的文件。 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". 在我的例子中,相应的消息是“无法设置PageSetup类的PaperSize属性”。 That occurs when the standard printer is not capable of the page format of the Excel workbook/sheet. 当标准打印机不具备Excel工作簿/工作表的页面格式时,会发生这种情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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