Check Outlook is open not working

constantG

Registered User.
Local time
Today, 10:13
Joined
Jun 24, 2009
Messages
92
Hi,

My application relies on whether Outlook is open and more importantly, with the correct Exchange profile selected. To ensure this I have the following code which, on the work PCs (Windows XP and Office 2003) works correctly.

Code:
If Outlook_is_Running = True Then
    Set myOlApp = CreateObject("Outlook.Application", "localhost")
    Set myNameSpace = myOlApp.GetNamespace("MAPI")
    Set colFolders = myNameSpace.Folders

On Error Resume Next
    famName = myNameSpace.GetDefaultFolder(olFolderInbox).Parent
    If InStr(1, famName, "OPB", vbTextCompare) Then
        Set folInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
        famName = "Familygrams_Send"
        Set folFamilygrams = myNameSpace.GetDefaultFolder(olFolderInbox).Folders(famName)
        
        If folFamilygrams Is Nothing Then
            folInbox.Folders.Add famName
        End If
        
        famName = "Familygrams_Received"
        Set folFamilygrams = myNameSpace.GetDefaultFolder(olFolderInbox).Folders(famName)
        
        If folFamilygrams Is Nothing Then
            folInbox.Folders.Add famName
        End If
    Else
        MsgBox "You have opened Outlook with the wrong profile"
        DoCmd.CancelEvent
        DoCmd.Quit
        Exit Sub
    End If
Else
    MsgBox "Outlook needs to be open and Macros enabled for the application to function."
    DoCmd.CancelEvent
    DoCmd.Quit
    Exit Sub
End If


Public Function Outlook_is_Running()
    
    Dim MyOL As Object
    
        On Error Resume Next
        
            Set MyOL = GetObject(, "outlook.Application")
            
            
            If Err.Number <> 0 Then
                Outlook_is_Running = False
            Else
                Outlook_is_Running = True
            End If
            Set MyOL = Nothing

End Function

The work PCs are being upgraded soon to Windows 7 and Office 2007 so I have taken the application home and started to develop it on my home PC (Windows 8.1 64 and Office 2013 64). I have used PtrSafe where necessary and have compiled with no errors, but this code always returns false even though Outlook 2013 is open.


Edit****** On further investigation, if I comment out the 'On Error Resume Next line I get the error Active X component cannot create the object (or similar) Error 429. This is the same regardless of whether Outlook is open or not

Any suggestions?
 
Last edited:
Throw out your Outlook_is_running function.

Use

Set myOlApp = CreateObject("Outlook.Application", "localhost")

whether or not Outlook is running - CreateObject is smart enough to know that only one instance is allowed, and to Get it, if one already is running.

Also, try without "localhost" - just with "Outlook.Application"
 
As for your specific issue, google presumably runs in your area:
outlook cannot create object 64
 
Google does but exact search syntax is not always at the forefront of my mind. Thanks for the spot.
 
After searching google I still can't get this to work.
 

Users who are viewing this thread

Back
Top Bottom