简体   繁体   English

VBA关闭Excel应用程序/工作簿冻结

[英]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. 都不起作用,它们都冻结并说它们正在等待OLE操作,并且如果我不调用这些操作,则我将打开多个excel进程,当我尝试打开通过代码打开的excel文件时,我只能以只读,因为它们已签出给我。

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. 我还尝试执行一个关闭所有应用程序“ Excel.Exe”的shell脚本,但是它关闭了……正在执行vba的实际excel文件,因此那不是一个好的解决方案。 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). Excel应用程序可能检测到工作簿已更改,并且正在弹出一个对话框(该对话框不可见,因为该应用程序不可见)。 Try: 尝试:

wb.Close False

Which tells Excel to ignore any changes to the workbook. 它告诉Excel忽略对工作簿的任何更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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