Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default how not close both Outlooks?

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default how not close both Outlooks?

"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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
email default in excel to Outlooks express? Jill Hatt Setting up and Configuration of Excel 1 February 24th 09 04:58 PM
why do all excel worksheets/workbooks close when I close one? Penny Excel Discussion (Misc queries) 1 November 29th 06 03:49 AM
close button does not close goplayoutside Excel Discussion (Misc queries) 1 October 11th 05 03:42 PM
Excel shoud not close all active books when clicking close button technomike Excel Discussion (Misc queries) 0 June 10th 05 05:35 PM
excel - Windows close button (x) should only close active workboo. CoffeeAdict Setting up and Configuration of Excel 3 February 8th 05 04:30 AM


All times are GMT +1. The time now is 02:47 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"