简体   繁体   中英

Vba closing excel applications/workbooks freezes

I have a problem with the following code:

Dim excelapp as object
set excelapp = CreateObject("excel.application")
dim ws as object
dim wb as Workbook

wb= excelapp.Workbooks.Open(path)
ws= wb.Sheets(1)
'in the code i send the worksheet object around by reference in order to read the
'worksheet and manipulate data, i dont create other instances of excel apps or
'workbooks

then i try :

wb.Close

and i have also tried :

excelapp.Quit

Neither have worked, they both freeze and say they are waiting on OLE actions, and i have multiple excel processes opening if i do not call these, when i try to open the excel files i had opened via code, i can only open them as read-only because theyre checked out to me.

I also tried executing a shell script that closes all applications "Excel.Exe" but it closes...the actual excel file where the vba is being executed, so thats not a good solution. Thank you in advance.

It might be that the Excel app has detected that the workbook has changed and is putting up a dialog box (which is invisible because the app is not visible). Try:

wb.Close False

Which tells Excel to ignore any changes to the workbook.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM