【发布时间】:2019-01-16 21:07:01
【问题描述】:
尝试在装有 MS Office 365 的 PC 中运行下面提到的脚本时,它运行良好,但如果我尝试在装有 MS Office 2003 的 PC 中运行相同的脚本,则会出现错误。
Windows 脚本主机
36号线
字符 17
工作簿类的错误 SaveAs 方法失败
代码 800A03EC
源 Microsoft Office Excel
目标:每隔一分钟将指定文件夹中的所有 CSV 文件转换为 XLS。如上所述,它在安装了 Office 365 的机器上运行良好,但如果我在安装了 Office 2003 的机器上运行它会报错。它们都是独立的机器。请帮我解决这个兼容性问题,这样我就可以在安装了 MS Office 2003 的机器上运行这个脚本。
Dim waittime: waittime = 1 * 60 * 1000
'Constants
Const xlOpenXMLWorkbook = 51 '(without macro's in 2007-2016, xlsx)
Const xlOpenXMLWorkbookMacroEnabled = 52 '(with or without macro's in 2007-2016, xlsm)
Const xlExcel12 = 50 '(Excel Binary Workbook in 2007-2016 with or without macro's, xlsb)
Const xlExcel8 = 56
Do
' Extensions for old and new files
strExcel = "xls"
strCSV = "csv"
' Set up filesystem object for usage
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Access the folder to process
Set objFolder = objFSO.GetFolder("C:\Users\User\Desktop\CSV to XL")
' Load Excel (hidden) for conversions
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = False
objExcel.DisplayAlerts = False
' Process all files
For Each objFile In objFolder.Files
' Get full path to file
strPath = objFile.Path
' Only convert CSV files
If LCase(objFSO.GetExtensionName(strPath)) = LCase(strCSV) Then
' Display to console each file being converted
'WScript.Echo "Converting """ & strPath & """"
' Load CSV into Excel and save as native Excel file
Set objWorkbook = objExcel.Workbooks.Open(strPath, False, True)
objWorkbook.SaveAs Replace(strPath, strCSV, strExcel), xlOpenXMLWorkbook
objWorkbook.Close False
Set objWorkbook = Nothing
End If
Next
WScript.Sleep (waittime)
Loop
【问题讨论】:
-
工作簿中有多少数据? excel 2003 只能处理 65536 行和 256 列。 o365 可以处理 1,048,576 行和 16,384 列。
-
肯定在这些数字之内。实际上,行和列不会超过两位数。