【发布时间】:2021-05-03 12:45:26
【问题描述】:
我检查了Excel Application not Closing from Outlook 并尝试了投票答案中的解决方案。
为了确保我没有做任何其他事情,我为 Outlook 编写了最简单的宏,只打开和关闭 Excel。这不是世界末日,因为这个后台进程几乎不会从内存中消耗任何东西,但它只会在 Outlook(谁调用它)关闭时关闭。
我把它放在“ThisOutlookSession”中:
Public Sub Test()
MsgBox "Trying"
Dim exApp As Excel.Application
Set exApp = Excel.Application
exApp.EnableEvents = False 'Originally I didn't placed this, but I saw it on the other posts
exApp.DisplayAlerts = False 'Originally I didn't placed this, but I saw it on the other posts
exApp.Visible = False 'Originally I didn't placed this, but I saw it on the other posts
exApp.Quit
Set exApp = Nothing
MsgBox "Finished"
End Sub
在 Office 2010 和 2016 上试用,结果相同。
【问题讨论】:
-
Set exApp = GetObject("Excel.Application")而不是= Excel.Application工作? -
你真的写的是
Set exApp = Excel.Application,还是Set exApp = New Excel.Application -
抱歉,K.Davis,你说得对:不是 GetObject(我在内存位置遇到运行时错误),但“CreateObject("Excel.Application")" 造成了我不知道的区别就是那个;拜托,只需将其添加为答案,以便我可以将问题标记为已回答,非常感谢您
-
你是早期绑定:
Dim exApp As Excel.Application。为了保持一致,您应该使用Set exApp = New Excel.Application而不是CreateObject。后者是后期绑定。