paganji
asked on
Open MS Outlook using VB
Hi Experts. I am using a MS Access database with VB. I wish to open outlook 2003 using code. I have attempted it using the following code but sometimes it works, and other times it gives an error saying "the operation failed" I cant explain why. Basically I only want it to open outlook if it is not open already. Thanks for any help.
Sub CheckIfOutlookIsRunning()
Dim oOutlook As Object
Dim oNameSpace As Object
Dim oInbox As Object
Set oOutlook = CreateObject("Outlook.Application")
Set oNameSpace = oOutlook.GetNamespace("MAPI")
Set oInbox = oNameSpace.GetDefaultFolder(6)
oOutlook.Quit 'Close All Outlook copies if open
oInbox.Display 'Open/show Outlook
End Sub
That was harder than I thought ... try the following. If outlook is already open it will however open a new view on the folder.
Chris
Chris
Sub CheckIfOutlookIsRunning()
Dim oOutlook As Object
Dim oNameSpace As Object
Dim oInbox As Object
Dim expl As Variant
Set oOutlook = CreateObject("Outlook.Application")
Set oNameSpace = oOutlook.GetNamespace("MAPI")
Set oInbox = oNameSpace.GetDefaultFolder(6)
Set expl = oOutlook.explorers.Add(oInbox, olFolderDisplayNoNavigation)
expl.display
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Chris Bottomley, you truely are an expert. Many thanks for your help. The code worked perfectly.
Glad to help and thank you for the grade
Chris
Chris
oOutlook.Quit 'Close All Outlook copies if open