Wednesday, 27 April 2016

How To Check If Outlook Application is open by using VBA code / Outlook Open ?

When you play around with outlook macros to send mails, get mail data, etc, You will face an issue whether the end user has not opened the outlook.

If the outlook is not open when you run the code, you cannot get the desired results and your code will stop.

I made a simple code to check if the outlook is open while you run the code.

This can be used from Both Excel or Acces.

Sub CheckOutlookIsOpen()
    Dim oOutlook As Object
    On Error Resume Next
    Set oOutlook = GetObject(, "Outlook.Application")
    On Error GoTo 0
    If oOutlook Is Nothing Then
        MsgBox "Error : Outlook is not open! This cannot be run without opening outlook", vbCritical, "Error"
    End If
End Sub