Test if Outlook is Available (1 Viewer)

micks55

Registered User.
Local time
Today, 08:04
Joined
Mar 20, 2006
Messages
110
Hi,
I'm sending emails ok when Outlook is loaded on the machine but failing when it is not. I've searched everywhere and am getting answers about how to resolve it.

The thing is, I'm not good enough to try to get to grips with discovering whatever email the machine may have and I'm happy to say "No Outlook, No emails" so how to I test to see if Outlook is available?

My code is failing when it gets to
Set objOutlook = CreateObject("Outlook.Application")

I've tried testing objOutlook for IsNull, IsEmpty or = "" but these tests are after the error and the code fails before it reaches them.
Thanks, Mike


UPDATE. If you keep looking you can find it...
Dim appOutlook As Outlook.Application
On Error Resume Next
Set appOutlook = CreateObject("Outlook.Application")
If Err.Number = 429 Then
MsgBox "You Do Not have Outlook Installed"
Exit Sub
End If

Problem solved.
 
Last edited:

darbid

Registered User.
Local time
Today, 09:04
Joined
Jun 26, 2008
Messages
1,428
to make your solution a little bit better check out getobject as well. This is good for people that already have an office program open. I think that most people have outlook open and your code will create a new instance of outlook.
 

boblarson

Smeghead
Local time
Today, 00:04
Joined
Jan 12, 2001
Messages
32,059
To go with darbid's response -

First start with
Code:
Dim ol As Object
 
Set ol = GetObject(,"Outlook.Application")
and if that errors out (you can use On Error Resume Next just before it) then use

Code:
Set ol = CreateObject("Outlook.Application")
 
If err.Number <> 0 Then 
   Msgbox "Outlook is not installed on this machine."
   Exit Function ' or Exit Sub if you are using a Sub
End If
 
On Error GoTo Err_Handler ' or whatever your error handler name is
 
'[...the rest of your code here]
 

micks55

Registered User.
Local time
Today, 08:04
Joined
Mar 20, 2006
Messages
110
Thanks guys, will try to improve my code.
Mike
 

darbid

Registered User.
Local time
Today, 09:04
Joined
Jun 26, 2008
Messages
1,428
it should also give you a 429 error. Also you can use this same idea for all office programs.
 

micks55

Registered User.
Local time
Today, 08:04
Joined
Mar 20, 2006
Messages
110
Hi Darbid and Bob. Still not quite getting there. Am trying to first test if Outlook is running then, if not, is it loaded.
Tried it on a machine without Outlook and now on a machine where Outlook is loaded but not running. I'm always getting error 429 twice unless Outlook is actually running.

On Error Resume Next
Dim ol As Object
Set ol = GetObject(, "Outlook.Application")
If Err.Number <> 0 Then
MsgBox Err.Number & " Outlook is not running."
' Exit Sub or Function
End If

Dim objOutlook As Outlook.Application
Set objOutlook = CreateObject("Outlook.Application")
If Err.Number <> 0 Then
MsgBox Err.Number & " You Do Not have Outlook Installed"
Else
MsgBox "Outlook is installed"
' Exit Sub or Function
End If

It only gets to "Outlook is installed" when Outlook is running.

With the code, Outlook has to be running (it fails if I havn't started Outlook)
Without the code the email goes even when Outlook is not running (but will fail if Outlook is not on the machine).

As you can see, I'm confused. Thanks Mike
 
Last edited:

JANR

Registered User.
Local time
Today, 09:04
Joined
Jan 21, 2009
Messages
1,623
Try this code:

Code:
Function testOutlook()
Dim oObj As Object
 
On Error Resume Next
Set oObj = GetObject(, "Outlook.Application")
    If Err.Number <> 0 Then
        ' No Outlook is not open, try and create object
        Err.Clear
        Set oObj = CreateObject("Outlook.Application")
            If Err.Number <> 0 Then
                MsgBox " Outlook Not Installed"
                Err.Clear
                GoTo ExitPoint
            End If
    End If
    '.... rest of code
 
ExitPoint:
oObj.Close
Set oObj = Nothing
Exit Function
 
End Function

JR
 
Last edited:

Users who are viewing this thread

Top Bottom