Microsoft Excel

Ron de Bruin
Excel Automation

Microsoft MVP Program

Get Default Mail program in Office 2011

Not working in older OS X versions before Leopard (Mac OS X 10.5).
You can use this in your Office 2011 code to test the default mail program.

Note: Please report if you have problems with the code below.

Note: Code like I show you below is also used in this mail add-in for Excel to know if Outlook or Apple Mail is the default mail program: RDBMail Mail Add-in for Excel/Outlook or Apple Mail

Note: For VBA code examples to mail from Excel visit : Send Mail from Mac Excel

 

Run the macro named WhichMailProgram to get the default mail program (note: this macro will call the function DefaultMailProgram so be sure that you copy this also in the macro module.

Note : This is not working in Mac Office 2016 on this moment

Sub WhichMailProgram()
    Select Case DefaultMailProgram
    Case "com.apple.mail": MsgBox "Default mail program is Apple Mail"
    Case "com.microsoft.outlook": MsgBox "Default mail program is Outlook"
    Case "com.microsoft.entourage": MsgBox "Default mail program is Entourage"
    Case Else: MsgBox "Unknown mail program"
    End Select
End Sub

Function DefaultMailProgram() As String
' Thanks to DJ Bazzie Wazzie from the macscripter forum, 5-Dec-2015
    Dim OSstring As String
    Dim OSVersion As String
    Dim MySplit As Variant
    Dim GetMailProgram As String

    OSstring = Application.OperatingSystem
    OSVersion = Right(OSstring, Len(OSstring) - InStrRev(OSstring, " ", , 1))
    MySplit = Split(OSVersion, ".")

    If Val(MySplit(0)) = 10 And Val(MySplit(1)) >= 5 And Val(MySplit(1)) <= 9 Then
    GetMailProgram = "do shell script ""defaults read com.apple.LaunchServices" & _
    "| (grep -B1 'mailto' || echo '\""com.apple.mail\""') | awk -F '\""' '{print $2;exit}'"""
    End If
    If Val(MySplit(0)) = 10 And Val(MySplit(1)) >= 10 Then
    GetMailProgram = "do shell script ""defaults read com.apple.LaunchServices/com.apple.launchservices.secure" & _
    "| (grep -B1 'mailto' || echo '\""com.apple.mail\""') | awk -F '\""' '{print $2;exit}'"""
    End If

    On Error Resume Next
    DefaultMailProgram = MacScript(GetMailProgram)
    On Error GoTo 0
End Function