0

I checked Excel Application not Closing from Outlook and tried the solution from the voted answer.

To make sure it was nothing else I was doing I wrote the simplest macro for Outlook to only open and close Excel. It's not the end of the world as this background process consumes almost nothing from memory, but it only closes when Outlook (who called it) closes.

I placed this in the "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

Tried on Office 2010 and 2016 with same results.

Community
  • 1
  • 1
SammuelMiranda
  • 420
  • 4
  • 29
  • `Set exApp = GetObject("Excel.Application")` instead of `= Excel.Application` work? – K.Dᴀᴠɪs May 03 '21 at 12:48
  • 2
    Did you really write `Set exApp = Excel.Application`, or `Set exApp = New Excel.Application` – BigBen May 03 '21 at 12:49
  • Sorry K.Davis, you're right: not GetObject (i get an runtime error at a memory position) but the "CreateObject("Excel.Application")" makes the difference i did not know it was the one; please, just add it as an answer so i can mark the question as answered, and thank you very much – SammuelMiranda May 03 '21 at 12:54
  • 1
    You are early-binding: `Dim exApp As Excel.Application`. To be consistent, you should use `Set exApp = New Excel.Application` instead of `CreateObject`. The latter is late-binding. – BigBen May 03 '21 at 13:00
  • https://stackoverflow.com/a/41801050/4539709 – 0m3r May 05 '21 at 12:28

1 Answers1

0

As reffered in the comments i just had to use "CreateObject("Excel.Application")" or "New Excel.Aplication" on the "set exApp = Excel.Application". Doing any of both works perfectlly.

SammuelMiranda
  • 420
  • 4
  • 29