2013-02-28 108 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