• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to check if MS Outlook is open?

inddon

Member
Hello There,

I have the below code which gets the info of the email id. I would like to add a check as follows:

1. Check if MS Outlook is open

If Yes then
proceed
else
display message
exit excel application
end if


Could you please advice, how the above can be achieved?

Thanks & regards,
Don



Code:
Public FirstName, LastName, DomainName, UserId As String
' ----------------------------------------------------------------
' Purpose: Get current user email address
' ----------------------------------------------------------------
Public Sub GetEmailAddress()
Dim SpacePos, TotalLen, Atsign As Integer
    With CreateObject("Outlook.Application").GetNamespace("MAPI")
         MsgBox .Items.Count
       
        'If .Session.CurrentUser.Address = "" Then
        '   MsgBox ("Your MS Outlook is not opened or configured")
        '   Exit Sub
        ' End If
       
        TotalLen = Len(.Session.CurrentUser.Address)
        SpacePos = InStr(1, .Session.CurrentUser, " ")
        FirstName = Left(.Session.CurrentUser, SpacePos - 1)
        Atsign = InStr(1, .Session.CurrentUser.Address, "@")
        DomainName = Right(.Session.CurrentUser.Address, TotalLen - Atsign)
        UserId = Left(.Session.CurrentUser.Address, Atsign - 1)
       
    End With
End Sub
 
Back
Top