【问题标题】:Excel Application not closing from Outlook VBAExcel 应用程序未从 Outlook VBA 关闭
【发布时间】: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。后者是后期绑定。

标签: excel vba outlook


【解决方案1】:

正如 cmets 中提到的,我只需要在“set exApp = Excel.Application”上使用“CreateObject(“Excel.Application”)”或“New Excel.Aplication”。两者中的任何一个都可以完美地完成。

【讨论】:

    猜你喜欢
    • 2018-03-24
    • 1970-01-01
    • 1970-01-01
    • 2011-04-07
    • 1970-01-01
    • 1970-01-01
    • 2016-08-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多