奇怪的是,cscript没有将xlsx保存为xlExcel8,并且无声地失败了



我使用msofice2010和cscript (Windows Script Version 5.8),试图做一些简单的事情:

  1. Open a native xlsx file 
  2. Save it as xls file (xlExcel8)

我所做的是:

<标题> xcx.vbs h1> ' http://msdn.microsoft.com/en-us/library/ff198017 (v = office.14) . aspx
  Const xlExcel8 = 56
  Set wdo = CreateObject("Excel.Application")
  Set wdoc = wdo.Workbooks.Open("c:pathtofoo.xlsx")
  wdoc.SaveAs "c:pathtobar.xls", xlExcel8
  wdoc.Close
  wdo.Quit

运行:

cscript xcx.vbs

然后,脚本完成,没有任何错误。但是我根本找不到c:pathtobar.xls

如果有人能告诉我正确的路,我会很感激的,谢谢:)

很奇怪,第一行没有出现错误。也许你在这个代码上面有On Error Resume Next ?试试这个:

Const xlExcel8 = 56

但是如果这个常量已经定义了,你也会得到类似"Name redefined"的错误,如果是这样,就删除那行

这真是让我发疯了!docx<->doc和Pptx<->ppt运行正常

我发现了一个现象(而不是解决方法),文件将被如果在目标' savea '之前添加了额外的浪费行,则已保存线。(见下面的注释代码)。

除了:

  1. 浪费的savea并没有真正的功能来保存东西(作为

  2. 如果浪费的savea试图保存为与目标相同格式的文件,则目标savea不起作用

我现在真的很晕,倾向于认为是MS Excel的bug,怎么回事声音吗?

Const xlExcel8          = 56
Const xlOpenXMLWorkbook = 51
Set wdo = CreateObject("Excel.Application")
Set wdoc = wdo.Workbooks.Open("c:pathtofoo.xlsx")
' This works, but only to save as bar.xls, which "resolved" my original problem
wdoc.SaveAs "c:pathtobar.xlsx", xlOpenXMLWorkbook 'Sacrificed line to *activate* the following line of saving ...
wdoc.SaveAs "c:pathtobar.xls",  xlExcel8
' This works, but only to save as bar.xlsx, 
' wdoc.SaveAs "c:pathtobar.xls",  xlExcel8  'Sacrificed line to *activate* the following line of saving ...
' wdoc.SaveAs "c:pathtobar.xlsx", xlOpenXMLWorkbook
' While this doesn't work at all
' wdoc.SaveAs "c:pathtobar.xls",  xlExcel8 
' wdoc.SaveAs "c:pathtobar.xls",  xlExcel8
wdoc.Close
wdo.Quit
Const xlExcel8 = 56
wdoc.ActiveWorkbook.SaveAs "c:pathtobar.xls", xlExcel8

最新更新