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.VBA code to Check: If Outlook Running - Open Outlook App if Not RunningVisual Basic12345678910111213141516171819202122Sub Is_Outlook_Running_Open_App()'Declare Variables to Check Get Instance of Outlook ObjectDim objOutlook As Object'InitializeSet objOutlook = Nothing'Get Instance of Object'Getobject will give error if it did not find the app.'Sp, On Error is required all the timeOn Error Resume NextSet objOutlook = GetObject(, "Outlook.Application")On Error GoTo 0'Check if Outlook is RunningIf objOutlook Is Nothing Then'Outlook is not Running - Open Outlook AppVBA.Shell ("Outlook")ElseMsgBox "Outlook is already Running in Your Machine"End IfEnd 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.
Outlook running or not – Why the check is performed?
When you are sending any automatic mass/bulk marketing emails using Vba, then Outlook will start sending the emails only when it is running. It is not enough to create an object.
For this purpose, we check if it is already running or not & then act accordingly.
Usually developers use late-binding for initiating an object with Outlook.Application. There is not much of a need to check whether it is already running or not.
If you are using early binding for Outlook App, then include reference to “Microsoft Outlook Library” from Tools -> References. Many times, this will be a problem, if the destination machine is having a lower version of Office than that you are coding.
So, it is better to use late-binding for Office Apps like Outlook & Word.
Previous Post: Convert Excel to HTML Table Tags – VBA Macro Code
Next Post: Create Keyboard Shortcut – to VBA Macro code – in Excel
Check If Outlook is Running – then Launch Outlook app – vba code