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.
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?
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: