How to Test if Outlook is Open or not?
Are you automating any task with Ms Outlook App? Then, sometimes, you need to verify that the Outlook is already running in machine or not. Here is the code... But wait... Read the important note below the code.Sub Is_Outlook_Running_Open_App()
'Declare Variables to Check Get Instance of Outlook Object
Dim objOutlook As Object
'Initialize
Set objOutlook = Nothing
'Get Instance of Object
'Getobject will give error if it did not find the app.
'Sp, On Error is required all the time
On Error Resume Next
Set objOutlook = GetObject(, "Outlook.Application")
On Error GoTo 0
'Check if Outlook is Running
If objOutlook Is Nothing Then
'Outlook is not Running - Open Outlook App
VBA.Shell ("Outlook")
Else
MsgBox "Outlook is already Running in Your Machine"
End If
End Sub
In the above code, the Vba.Shell command will open the Outlook Application if it is not already running.
Note: To explicitly open Outlook send/receive use this line in your vba code. ObjOutlook.Application.GetNamespace("MAPI").SendAndReceive (True)
Once this is executed, you can see that "Send/Receive" window is opened & Outlook will start processing the emails in outbox.