Set objOutlook = CreateObject("Outlook.Application")
It looks SO simple to fire up Outlook to do something via VBA automation.
Set objOutlook = GetObject(, "Outlook.Application")
This gets the open instance of Outlook for your use.
On Error Resume Next
Dim objOutlook As Outlook.Application
Set objOutlook = GetObject(, "Outlook.Application")
If Err.Number = 429 Then
Err.Clear
Set objOutlook = CreateObject("Outlook.Application")
End If
And you'll pat yourself on the back for a job well done...
Option Explicit
Public WasOpen As Boolean
Private Function FireOutlook() As Outlook.Application
On Error Resume Next
Dim objOutlook As Outlook.Application
Set objOutlook = GetObject(, "Outlook.Application")
'MsgBox Err.Number & " " & Err.Description
If Err.Number = 429 Then
Err.Clear
WasOpen = False
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
Else
WasOpen = True
End If
Set FireOutlook = objOutlook
End Function
Dim objOutlook As Outlook.Application
Set objOutlook = FireOutlook()
You may have noticed
WasOpen
Dim ns As Outlook.Namespace
Dim Folder As Outlook.MAPIFolder
Set ns = objOutlook.GetNamespace("MAPI")
Set Folder = ns.GetDefaultFolder(olFolderInbox)
Set objOutlookExplorers = objOutlook.Explorers
If WasOpen = False Then
objOutlook.Explorers.Add Folder
Folder.Display
'done opening
End If
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (3)
Commented:
Commented:
Commented:
On Error GoTo Err_Handler
...
...
Err_Handler:
If Err.Number = 429 Then
Err.Clear
Set oOutlookApp = GetObject(, "Outlook.Application")
Resume Next
Else
MsgBox Err.Number & " " & Err.Description
Resume Exit_Handler
End If