应用程序(SCADA程序)有一个事件,每天都会发生变化并运行一个写入Excel文件的脚本(每天一个)。该文件可能包含多个工作表。
在Windows 7上,安装了Office 2007,我可以写,但我无法保存,也没有退出Excel.Application
。
Dim objExcel as Object
Set objExcel = CreateObject("Excel.Application")
objExcel.WorkBooks.Add 'I think I shouldn't do this, but if not it doesn't work
Set sheet = objExcel.ActiveWorkBook.Worksheets.Add
'writing to the actual sheet...
objExcel.ActiveWorkBook.SaveAs path$
objExcel.Workbooks.Close
objExcel.Quit
如果我手动运行脚本(从脚本编辑器):
如果我尝试触发事件:
答案 0 :(得分:1)
解决。
Dim objExcel as Object
Dim sheet as Object
Set objExcel = CreateObject("Excel.Application")
objExcel.WorkBooks.Add
Set sheet = objExcel.ActiveWorkBook.Worksheets.Add
'writing to the actual sheet...
path$ = "path/must/use/slash/insteed/of/backslash"
objExcel.ActiveWorkBook.SaveAs path$
objExcel.ActiveWorkBook.Close
objExcel.Quit
Set objExcel = Nothing
所以问题是path$
,我忘了放Set objExcel = Nothing
。就这样。