Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks in advance.
I have an Excel macro that opens Outlook with 'shell' and set objOutlook=createObject, then closes it with objOutlook.Quit. But if I have two Outlooks open (one that was already open, and one more that was opened by the macro), the objOutlook.Quit closes them both. Is it possible to just close one? Thanks again. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
"Ian Elliott" wrote in message ...
Thanks in advance. I have an Excel macro that opens Outlook with 'shell' and set objOutlook=createObject, then closes it with objOutlook.Quit. But if I have two Outlooks open (one that was already open, and one more that was opened by the macro), the objOutlook.Quit closes them both. Is it possible to just close one? Thanks again. Hi Ian, I put this at the top of the code module where I interact with Outlook 'Declarations section Option Explicit Option Base 1 Public objOutlook As Outlook.Application Public objNamespace As Outlook.NameSpace Public OutlookWasRunning As Boolean 'Interface with Outlook objects required will be through this sub. 'It is called by any sub requiring access to Outlook. Public Sub DeclareOutlookObjects() Application.ScreenUpdating = False On Error Resume Next Err.Clear Set objOutlook = GetObject(, "Outlook.Application") 'If Outlook is already open, flag it with Boolean If Err.Number < 0 Then OutlookWasRunning = False Else OutlookWasRunning = True end if On Error GoTo 0 Err.Clear 'keep err tidy If Not OutlookWasRunning Then Set objOutlook = CreateObject("Outlook.Application") 'fresh version of Outlook End If Set objNamespace = objOutlook.GetNamespace("MAPI") objNamespace.Logon 'may not be needed End Sub 'Releases Public variable objects after Outlook session Public Sub ReleaseOutlookObjects() Application.ScreenUpdating = False objNamespace.Logoff Set objNamespace = Nothing If Not OutlookWasRunning Then objOutlook.Quit Set objOutlook = Nothing End Sub You can call the first sub before creating messages etc and the second when you are finished. There is only ever one copy of Outlook open - why have two? regards Paul |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
email default in excel to Outlooks express? | Setting up and Configuration of Excel | |||
why do all excel worksheets/workbooks close when I close one? | Excel Discussion (Misc queries) | |||
close button does not close | Excel Discussion (Misc queries) | |||
Excel shoud not close all active books when clicking close button | Excel Discussion (Misc queries) | |||
excel - Windows close button (x) should only close active workboo. | Setting up and Configuration of Excel |