2013-02-28 111 views
2

我用MSOffice2010和CSCRIPT(Windows脚本5.8版),试图做的事情就这么简单:奇怪CSCRIPT不保存XLSX为xlExcel8默默地失败

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

我所做的是:

xcx.vbs

'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:\path\to\foo.xlsx") 

    wdoc.SaveAs "c:\path\to\bar.xls", xlExcel8 

    wdoc.Close 

    wdo.Quit 

要运行它:

CSCRIPT xcx.vbs

然后,剧本完成后没有任何错误。但我根本找不到c:\path\to\bar.xls

我会很感激,如果有人能告诉我一个正确的方式去,谢谢:)

回答

0

很奇怪,你有没有错误的第一道防线。也许你在此代码上面有On Error Resume Next?试试这个:

Const xlExcel8 = 56 

但如果常量已经被定义,你会得到错误太像“名称重新定义”,如果是这样,只是删除了这一行。

+0

Panayot,感谢您的答复,我只是太急于生类的东西我的代码的另一台计算机上:)而问题仍然存在,与“=”正确的常量。为了避免误解,我得到**更新**的问题。 – fantuan 2013-02-28 12:58:47

+0

我明白了,那么我的回答完全没有帮助:) – 2013-02-28 13:56:02

0

这真的让我疯了! docx < - > doc和 pptx < - > ppt的对应模拟代码工作正常。

而且我发现一个现象(而不是workround),该文件将是,如果一个额外的浪费线加提前锁定“另存为” 线 保存。 (请参阅下面的注释代码)。

除了:

  1. 浪费另存为并没有真正有功能保存的东西(如 原问题)

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

我真的晕了现在倾向于认为一个MS Excel中的错误,怎么就这么 声音?

Const xlExcel8   = 56 
Const xlOpenXMLWorkbook = 51 

Set wdo = CreateObject("Excel.Application") 

Set wdoc = wdo.Workbooks.Open("c:\path\to\foo.xlsx") 

' This works, but only to save as bar.xls, which "resolved" my original problem 
wdoc.SaveAs "c:\path\to\bar.xlsx", xlOpenXMLWorkbook 'Sacrificed line to *activate* the following line of saving ... 
wdoc.SaveAs "c:\path\to\bar.xls", xlExcel8 

' This works, but only to save as bar.xlsx, 
' wdoc.SaveAs "c:\path\to\bar.xls", xlExcel8 'Sacrificed line to *activate* the following line of saving ... 
' wdoc.SaveAs "c:\path\to\bar.xlsx", xlOpenXMLWorkbook 

' While this doesn't work at all 
' wdoc.SaveAs "c:\path\to\bar.xls", xlExcel8 
' wdoc.SaveAs "c:\path\to\bar.xls", xlExcel8 

wdoc.Close 

wdo.Quit 
0
Const xlExcel8 = 56 

wdoc.ActiveWorkbook.SaveAs "c:\path\to\bar.xls", xlExcel8