colindow
asked on
Handling an instance of outlook
I have a form which loads an instance of outlook.
When the form is closed I quit the instance.
It all works fine but what I would like is some way of checking whether the user has outlook open when I load the form and then act accrdingly when I close the form.
At present my code unloads outlook regardless of its state when the form loaded
i.e
Function InitOutlook() As Integer
On Error Resume Next
InitOutlook = False
statBar.Panels(1).Text = "Creating Outlook application link...."
Set appOut = CreateObject("Outlook.Appl ication")
If appOut Is Nothing Then
Set appOut = New Outlook.Application
End If
statBar.Panels(1).Text = ""
If appOut Is Nothing Then
MsgBox "Error instantiating outlook" & Err.Description
Exit Function
End If
statBar.Panels(1).Text = "Creating Outlook Namespace...."
Set mNS = appOut.GetNamespace("MAPI" )
If Err Then
MsgBox "Error creating NameSpace " & Err.Description
Exit Function
End If
statBar.Panels(1).Text = ""
InitOutlook = True
End Function
Then on unload
set mNS = nothing
appout.quit
set appout = nothing
When the form is closed I quit the instance.
It all works fine but what I would like is some way of checking whether the user has outlook open when I load the form and then act accrdingly when I close the form.
At present my code unloads outlook regardless of its state when the form loaded
i.e
Function InitOutlook() As Integer
On Error Resume Next
InitOutlook = False
statBar.Panels(1).Text = "Creating Outlook application link...."
Set appOut = CreateObject("Outlook.Appl
If appOut Is Nothing Then
Set appOut = New Outlook.Application
End If
statBar.Panels(1).Text = ""
If appOut Is Nothing Then
MsgBox "Error instantiating outlook" & Err.Description
Exit Function
End If
statBar.Panels(1).Text = "Creating Outlook Namespace...."
Set mNS = appOut.GetNamespace("MAPI"
If Err Then
MsgBox "Error creating NameSpace " & Err.Description
Exit Function
End If
statBar.Panels(1).Text = ""
InitOutlook = True
End Function
Then on unload
set mNS = nothing
appout.quit
set appout = nothing
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Agree with bobbit31 that using GetObject to see whether an Object instance is opened.
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
if findwindow(vbnullstring, "Outlook") > 0 then
init = true
else
init = false
end if