Solved

Handling an instance of outlook

Posted on 2002-03-06
3
166 Views
Last Modified: 2010-05-02
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.Application")
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
0
Comment
Question by:colindow
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
bobbit31 earned 150 total points
ID: 6844661
on Error Resume Next

init = true
set appOut = GetObject(, "Outlook.Application")
if err.number <> 0 then
   init = false
   Set appOut = CreateObject("Outlook.Application")
end if




0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6844689
or alternatively you can search for the window using findwindow api

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
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 6846037
Agree with bobbit31 that using GetObject to see whether an Object instance is opened.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now