我遇到了一个vbscript的问题,它创建Excel对象并从Excel文件中读取。
从Excel宏执行vbscript,然后创建并打开Excel文件并从中读取。问题是Excel对象并不总是关闭的,即使我试图关闭它。
下面是vbscript中的代码:
Set ExcelObject = createobject("Excel.Application")
ExcelObject.workbooks.open testWorkBookPath
Set testActionArray = CreateObject( "System.Collections.ArrayList" )
Function getTestsCaseActions (testsPath, esheet, row, col)
Set my_sheet = ExcelObject.sheets.item(esheet)
tempArray = array(my_sheet.cells(row, col-2), "")
testActionArray.Add tempArray
Do While my_sheet.cells(row, col).Value <> ""
tempArray = array(my_sheet.cells(row, col), my_sheet.cells(row+1, col))
testActionArray.Add tempArray
col = col+1
Loop
End Function
getTestsCaseActions testWorkBookPath, testCaseSheet, 3, 4
ExcelObject.Quit
现在,如果我运行上述代码并查看,则在脚本启动时生成一个新的Excel进程,然后按照预期关闭。
但是,如果在运行函数后,在ExcelObject.Quit行之前插入此代码:
For Each ArrayItem in testActionArray
IF ArrayItem(1) = "" Then
Wscript.Echo ArrayItem(0)
Else
Wscript.Echo ArrayItem(0) & " -> " & ArrayItem(1)
End If
Next
ExcelObject.Quit (STILL HERE)
然后派生的进程不会退出,进程列表会增长,直到Excel完全崩溃为止。
我不明白这一点;最后一点代码所做的就是循环遍历ArrayList并打印内容。为什么这个过程不退出?
编辑:看起来至少有一些Excel对象最终从Process中消失了,但是这需要20到30分钟。只是其中的几个-大部分还在。至少目前我的列表已经缩小了一些,但是仍然有大约15个Excel进程在运行。
此外,这条信息突然出现:
File Now Available
'filename.xlsm ' is now available for editing. Choose Read-Write to open it for editing.
发布于 2013-11-09 08:44:59
这句话似乎很有帮助。它并没有完全删除所有额外的进程,但是这个数字增长到5个,然后返回到两个,依此类推。所以效果很好。
dim book: for each book in ExcelObject.Workbooks: book.saved = true: next
https://stackoverflow.com/questions/19838433
复制相似问题