A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Outlook 2003 Instance Won't Close If Opened Programmatically



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old January 9th 06, 07:26 AM posted to microsoft.public.outlook.program_vba
Michael Bauer
external usenet poster
 
Posts: 435
Default Outlook 2003 Instance Won't Close If Opened Programmatically

Am Fri, 06 Jan 2006 08:59:26 -0600 schrieb Gman:

If the user canīt quit OL then your app is still running - or any other app
that holds at least one ref on OL. You need to check your code that really
nothing remains alive. A popular mistake e.g. is not to unload a form.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook



Hi Michael,

Thanks for your response. Unfortunately, if I use
myExpl.Close
then
oOL.Application.Quit
and then I release any objects associated with Outlook

Set myFolder = Nothing
Set myExpl = Nothing
Set myNameSpace = Nothing
Set oOL = Nothing

it still doesn't allow my application to kill Outlook.

Also, I'm not really looking to kill Outlook from my application
(although I would like to be able to do this). Rather, when I need to
send emails, I want to open up Outlook (if it's not already open) and
send them, leaving it open for the user.

If the user closes my application, I would prefer to leave Outlook
running - they may well be using it. But when they come to close Outlook
themselves, it won't close if I created the instance -- even if my
application is no longer open.

Thanks

Revised code:
Sub OpenOutlook2()

Dim oOL As Object
Dim myNameSpace As Object, myExpl As Object

'Try and get an active instance:
On Error Resume Next
Set oOL = GetObject(, "Outlook.Application")
On Error GoTo 0

If oOL Is Nothing Then
'try and create a new instance
Set oOL = CreateObject("Outlook.Application")
If Not oOL Is Nothing Then

Set myNameSpace = oOL.GetNamespace("MAPI")

Set myExpl = _
oOL.Explorers.Add(myNameSpace.GetDefaultFolder(6), 0)
'olFolderInbox,'olFolderDisplayNormal
myExpl.Activate
MsgBox "opening...."

End If
End If

If MsgBox("Outlook created = " & (oOL Is Nothing) _
& vbCrLf & "Wanna close?", vbYesNo) = vbYes Then
myExpl.Close
oOL.Application.Quit
End If

'tidy up....
Set myExpl = Nothing
Set myNameSpace = Nothing
Set oOL = Nothing

End Sub


Michael Bauer wrote:
Am Thu, 05 Jan 2006 22:32:28 -0600 schrieb Gman:

I think, closing the Explorer by code, if you created the OL instance,
should do it.

Ads
  #2  
Old January 9th 06, 02:43 PM posted to microsoft.public.outlook.program_vba
Gman
external usenet poster
 
Posts: 4
Default Outlook 2003 Instance Won't Close If Opened Programmatically

Hi Michael,

I understand your post - but I believe this isn't the case since:

(a) The app in question is a test application consisting of one form and
the code at the foot of this post -- that's it! You can see that
everything is released - there are no other variables or objects in the
application.

(b) If Outlook was opened by my app and then my app is closed -- I check
in Task Manager that my app is no longer running, when I try and
manually close Outlook I still get the problem. Therefore it's not my
app holding onto something, more it's Outlook not being opened / made
visible correctly. Maybe it's something to do with the namespace?!

(c) It works fine on Outlook 2000 under Win2K.

Thanks again,
Gman

'entire code of project
Option Explicit

Private Sub butClose_Click()
Unload Me
End Sub

Private Sub butGetOutlook_Click()
Call OpenOutlook
End Sub

Sub OpenOutlook()

Dim oOL As Object
Dim myNameSpace As Object, myExpl As Object

'Try and get an active instance:
On Error Resume Next
Set oOL = GetObject(, "Outlook.Application")
On Error GoTo 0

If oOL Is Nothing Then
'try and create a new instance
Set oOL = CreateObject("Outlook.Application")
If Not oOL Is Nothing Then

Set myNameSpace = oOL.GetNamespace("MAPI")

Set myExpl = _
oOL.Explorers.Add(myNameSpace.GetDefaultFolder(6), 0)
'olFolderInbox,'olFolderDisplayNormal
myExpl.Activate

End If
End If

'tidy up....
Set myExpl = Nothing
Set myNameSpace = Nothing
Set oOL = Nothing

End Sub
  #3  
Old January 11th 06, 07:19 AM posted to microsoft.public.outlook.program_vba
Michael Bauer
external usenet poster
 
Posts: 435
Default Outlook 2003 Instance Won't Close If Opened Programmatically

Am Mon, 09 Jan 2006 08:43:21 -0600 schrieb Gman:

Sorry, I donīt know what the problem is. If weird things happen then NAV is
often a good point to look at... :-)

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook



Hi Michael,

I understand your post - but I believe this isn't the case since:

(a) The app in question is a test application consisting of one form and
the code at the foot of this post -- that's it! You can see that
everything is released - there are no other variables or objects in the
application.

(b) If Outlook was opened by my app and then my app is closed -- I check
in Task Manager that my app is no longer running, when I try and
manually close Outlook I still get the problem. Therefore it's not my
app holding onto something, more it's Outlook not being opened / made
visible correctly. Maybe it's something to do with the namespace?!

(c) It works fine on Outlook 2000 under Win2K.

Thanks again,
Gman

'entire code of project
Option Explicit

Private Sub butClose_Click()
Unload Me
End Sub

Private Sub butGetOutlook_Click()
Call OpenOutlook
End Sub

Sub OpenOutlook()

Dim oOL As Object
Dim myNameSpace As Object, myExpl As Object

'Try and get an active instance:
On Error Resume Next
Set oOL = GetObject(, "Outlook.Application")
On Error GoTo 0

If oOL Is Nothing Then
'try and create a new instance
Set oOL = CreateObject("Outlook.Application")
If Not oOL Is Nothing Then

Set myNameSpace = oOL.GetNamespace("MAPI")

Set myExpl = _
oOL.Explorers.Add(myNameSpace.GetDefaultFolder(6), 0)
'olFolderInbox,'olFolderDisplayNormal
myExpl.Activate

End If
End If

'tidy up....
Set myExpl = Nothing
Set myNameSpace = Nothing
Set oOL = Nothing

End Sub

  #4  
Old January 11th 06, 03:19 PM posted to microsoft.public.outlook.program_vba
Gman
external usenet poster
 
Posts: 4
Default Outlook 2003 Instance Won't Close If Opened Programmatically

OK - I'll take a look at that. Possibly it's just my Outlook
installation. I've had no complaints from clients who use the full
application - but then again maybe they haven't noticed...

Thanks for getting back to me - I appreciate your time.

Gman

Michael Bauer wrote:
Am Mon, 09 Jan 2006 08:43:21 -0600 schrieb Gman:

Sorry, I donīt know what the problem is. If weird things happen then NAV is
often a good point to look at... :-)

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Outlook 2003 does not close down correctly.. No info why SusanDes Outlook - Installation 1 February 20th 06 07:01 PM
Outlook 2003 fires an Inspector Close when a send is cancelled Steve D Add-ins for Outlook 8 February 8th 06 11:22 PM
Cannot close archive.pst folder in Outlook 2003 Clark Outlook - General Queries 2 January 31st 06 08:27 AM
outlook folders can not be opened chris the badger Outlook - Installation 2 January 23rd 06 09:13 PM
Calendar... Button opens another Outlook Instance ... Sue Mosher [MVP-Outlook] Outlook - Calandaring 0 January 19th 06 09:09 PM


All times are GMT +1. The time now is 09:10 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright Đ2004-2025 Outlook Banter.
The comments are property of their posters.