2

私は MSOffice2010 と cscript (Windows Script Version 5.8) を使用して、次のような簡単なことをしようとしていました。

  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

誰かが正しい道を教えてくれたらありがたいです、ありがとう:)

4

3 に答える 3

0

最初の行にエラーがないのは不思議です。多分あなたはOn Error Resume Nextこのコードの上にありますか?これを試して:

Const xlExcel8 = 56

ただし、その定数がすでに定義されている場合は、「名前が再定義されました」のようなエラーが発生します。その場合は、その行を削除してください。

于 2013-02-28T10:50:57.123 に答える
0
Const xlExcel8 = 56

wdoc.ActiveWorkbook.SaveAs "c:\path\to\bar.xls", xlExcel8
于 2013-08-14T22:49:50.927 に答える
0

これは本当に私を夢中にさせました!docx<->doc と pptx<->ppt の対応する simlar コードはスムーズに動作しました。

そして、対象の「SaveAs」行の前に余分な無駄な行を追加すると、ファイルが保存されるという現象 (回避策ではなく) を発見しました。(以下のコメント付きコードを参照してください)。

その上:

  1. 無駄なSaveAsには、物事を保存する機能が実際にはありません(元の問題として)

  2. 無駄な SaveAS がターゲットと同じ形式のファイルとして保存しようとしている場合、ターゲットの SaveAs は機能しません。

私は今、本当にめまいがして、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
于 2013-03-01T07:05:48.970 に答える