0

I've got a problem with a vbscript which creates Excel objects and reads from an Excel file.

The vbscript is executed from an Excel macro, and then creates and opens the Excel file and reads from it. The problem is that the Excel object isn't allways closed, even though I'm trying to to it.

Here's the code from the 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

Now, if I run the above code and watch the process explorer, a new Excel process is spawned when the script is started, and then closes, as expected.

However, if I insert this code after running the function, before the ExcelObject.Quit line:

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)

then the spawned process does NOT quit, and the process list grows until Excel goes completely bananas.

I don't understand this; All the last bit of code does is loop through the ArrayList and print the contents. Why's not the process quitting?

EDIT: At seems that at least some of the Excel objects eventually disappear from the Process Explorer, but this takes about 20-30 minutes. And it's just a few of them - most are still there. At least my list at the moment has shrinked some, but there are still about 15 Excel processes running.

Also, suddenly this message appears:

File Now Available
'filename.xlsm ' is now available for editing. Choose Read-Write to open it for editing.
4

1 回答 1

0

这条线似乎有帮助。它并没有完全删除所有额外的进程,但数量会增长到五个,然后又回到两个,依此类推。所以它工作得很好。

dim book: for each book in ExcelObject.Workbooks: book.saved = true: next 
于 2013-11-09T08:44:59.970 回答