从xlsx转换为mht错误:Microsoft Office Excel:SaveAs方法的Workbook类失败

时间:2015-11-18 14:36:49

标签: excel excel-vba vbscript vba

我有一个VBScript,它使用Excel 2007从xlsx转换为mht。这是VBScript

' This script takes two parameters
' $1: XLSX Filename (should be full path if possible, with ending)
' $2: MHT Filename (should be full path if possible, with ending)

' Constant definitions
Const xlWebArchive = 45

' Store the arguments in a variable:
Set objArgs = Wscript.Arguments
XLSX_Filename = Wscript.Arguments.Item(0)
MHT_Filename = Wscript.Arguments.Item(1)

Wscript.Echo "XLSX Filename: " & XLSX_Filename
Wscript.Echo "MHT Filename: " & MHT_Filename

' Create an instance of Excel and open the workbook...
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Open XLSX_Filename

' Save the workbook as an MHTML page...
objExcel.ActiveWorkbook.SaveAs MHT_Filename, xlWebArchive

' Close Excel...
objExcel.Quit

但是使用该方法,我收到错误:

xlsx_to_mht.vbs(24, 1) Microsoft Office Excel: SaveAs method of Workbook class failed

这是

objExcel.ActiveWorkbook.SaveAs MHT_Filename, xlWebArchive

那么为什么会出错呢?

编辑:脚本的示例输出

# converting from xlsx to mht
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.

XLSX Filename: C:\path\to\project\ThirdPartyLicense.xlsx
MHT Filename: C:\path\to\project\ThirdPartyLicense.mht
C:\path\to\vbscript\xlsx_to_mht_conv\xlsx_to_mht.vbs(24, 1) Microsoft Office Excel: SaveAs method of Workbook class failed

1 个答案:

答案 0 :(得分:0)

我想我找到了解决方案(就我而言)。我试过像Scott Holtzman建议的那样,在Excel中手动打开该文件并查看Excel的功能。 Excel未激活。我激活了它。错误消失了。