G
Gman
Hi NG,
I recently modified some emailing code in one of my existing VB6
applications such that when I create an Outlook instance I make it
visible. I now find that when the app *creates* the instance (there's no
problem if I use GetObject to grab an existing instance) whether Outlook
is closed by my app or by the user (ALT F4, File Exit, X button etc)--
even after my application has closed -- Outlook just disappears but
still appears in Task Manager.
After half a day of troubleshooting I created a tiny app with one button
that runs the code pasted below. (That's the only code in the
application other than a button click event to run the sub.)
I'm running Outlook 2003 (11.6568.6568) SP2 on XP Home. Note that I
don't actually have an exchange server to connect to - I use this purely
for development.
I ran it on a Win2K machine running Office 2000 and everything behaved
perfectly. Note further that it also runs fine (i.e. I can close Outlook
w/o problems) on my XP machine providing I don't make Outlook visible.
There's posting galore on this topic - which I've read - I don't really
see what I can be doing incorrectly.
Any help gratefully received.
Thanks
Sub OpenOutlook()
Dim oOL 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
'let's try and create a new instance
Set oOL = CreateObject("Outlook.Application")
If Not oOL Is Nothing Then
Dim myNameSpace As Object, myFolder As Object, myExpl As Object
Set myNameSpace = oOL.GetNameSpace("MAPI")
'if we do find it, we should make it visible'
'there's (at least) two ways of doing this - both of
'which give me the same problem
If MsgBox("Use Explorer method? " _
& "(Otherwise, will use folder method...)" _
, vbYesNo) = vbYes Then
Set myExpl = _
oOL.explorers.Add(myNameSpace.GetDefaultFolder(6), 0)
'''olFolderInbox,'olFolderDisplayNormal
myExpl.Activate
Else
Set myFolder = myNameSpace.GetDefaultFolder(6)
'olFolderInbox
myFolder.Display
End If
Set myFolder = Nothing
Set myExpl = Nothing
Set myNameSpace = Nothing
End If
End If
'Here's some code to delay closing Outlook
'I put this here for testing purposes - I get the problem
'with or without this - i.e. whether I close OL
'programmatically or manually
If MsgBox("Outlook created = " & (oOL Is Nothing) _
& vbCrLf & "Wanna close?", vbYesNo) = vbYes Then _
oOL.application.quit
'tidy up....
Set oOL = Nothing
End Sub
I recently modified some emailing code in one of my existing VB6
applications such that when I create an Outlook instance I make it
visible. I now find that when the app *creates* the instance (there's no
problem if I use GetObject to grab an existing instance) whether Outlook
is closed by my app or by the user (ALT F4, File Exit, X button etc)--
even after my application has closed -- Outlook just disappears but
still appears in Task Manager.
After half a day of troubleshooting I created a tiny app with one button
that runs the code pasted below. (That's the only code in the
application other than a button click event to run the sub.)
I'm running Outlook 2003 (11.6568.6568) SP2 on XP Home. Note that I
don't actually have an exchange server to connect to - I use this purely
for development.
I ran it on a Win2K machine running Office 2000 and everything behaved
perfectly. Note further that it also runs fine (i.e. I can close Outlook
w/o problems) on my XP machine providing I don't make Outlook visible.
There's posting galore on this topic - which I've read - I don't really
see what I can be doing incorrectly.
Any help gratefully received.
Thanks
Sub OpenOutlook()
Dim oOL 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
'let's try and create a new instance
Set oOL = CreateObject("Outlook.Application")
If Not oOL Is Nothing Then
Dim myNameSpace As Object, myFolder As Object, myExpl As Object
Set myNameSpace = oOL.GetNameSpace("MAPI")
'if we do find it, we should make it visible'
'there's (at least) two ways of doing this - both of
'which give me the same problem
If MsgBox("Use Explorer method? " _
& "(Otherwise, will use folder method...)" _
, vbYesNo) = vbYes Then
Set myExpl = _
oOL.explorers.Add(myNameSpace.GetDefaultFolder(6), 0)
'''olFolderInbox,'olFolderDisplayNormal
myExpl.Activate
Else
Set myFolder = myNameSpace.GetDefaultFolder(6)
'olFolderInbox
myFolder.Display
End If
Set myFolder = Nothing
Set myExpl = Nothing
Set myNameSpace = Nothing
End If
End If
'Here's some code to delay closing Outlook
'I put this here for testing purposes - I get the problem
'with or without this - i.e. whether I close OL
'programmatically or manually
If MsgBox("Outlook created = " & (oOL Is Nothing) _
& vbCrLf & "Wanna close?", vbYesNo) = vbYes Then _
oOL.application.quit
'tidy up....
Set oOL = Nothing
End Sub