none
Mac - Reference Library: Outlook Object Library Reference Missing RRS feed

  • Question

  • Hi,

    I am trying to integrate MS Outlook with Excel in my Mac Book Pro. I have installed the MS Office package available for students in our university. 

    When I go to VBA -> Tools -> References, there is no Outlook library available. Only libraries for:

    MS Office 16.0
    MS Excel 16.0
    MS Forms 2.0
    MS PowerPoint 16.0
    MS Word 16.0
    MS Visual Basic for Applications Extensibility 5.3
    Visual basic for applications
    OLE Automation
    VBA project
    etc...

    So, why is the Outlook library not there? Is there any way to fix this, since I cannot make any automation without the library... or can I ??

    Any support would be greatly appreciated!

    Tuesday, March 13, 2018 11:34 PM

All replies

  • Hi Juhta,

    Currently, We are not available with MAC machine to verify that Outlook library is available or not.

    On my windows machine, I can use the late binding to create an object of Outlook application and then I can automate it without adding a reference to Outlook library.

    Below is an example code:

    Sub demo2()
      Dim xOutApp As Object
        Dim xOutMail As Object
        Dim xMailBody As String
        On Error Resume Next
        Set xOutApp = CreateObject("Outlook.Application")
        Set xOutMail = xOutApp.CreateItem(0)
        xMailBody = "Body content" & vbNewLine & vbNewLine & _
                  "This is line 1" & vbNewLine & _
                  "This is line 2"
                      On Error Resume Next
        With xOutMail
            .To = "Email Address"
            .CC = ""
            .BCC = ""
            .Subject = "Test email send by button clicking"
            .Body = xMailBody
            .Display   'or use .Send
        End With
        On Error GoTo 0
        Set xOutMail = Nothing
        Set xOutApp = Nothing
    End Sub
    

    So you can try the same on MAC and try to use late binding to automate Outlook without adding reference to Outlook library from Excel Application.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, March 14, 2018 7:12 AM
    Moderator
  • Thank you Deepak,

    I tried the code and... nothing happens. No error messages, but no result either. Changed the .display to .send but doesn't make a difference.

    Really sorry, I'm yet to become experienced in VBA scripting. Have made some minor scripts before, but nothing where an "external" connection (such as to Outlook) is created and used.

    Regards

    Juhani

    Wednesday, March 14, 2018 9:32 AM
  • I put an error handler into the code and it jumps to the error handler when reaching the line:
    Set xOutApp = CreateObject("Outlook.Application")

    This "createobject" function "Creates and returns a reference to an ActiveX object". 

    Now, I am able to create an excel object, such as:

    Dim ExcelSheet As Object

    Set ExcelSheet = CreateObject("Excel.Sheet")

    But the "Outlook.Application" object will cause an error message. Cleary there is some link between the applications missing.


    • Edited by Juhta Wednesday, March 14, 2018 10:30 AM
    Wednesday, March 14, 2018 10:29 AM
  • Hi Juhta,

    Is Outlook Application is installed and working correctly on your side?

    If possible then check for any pending updates, If available then install it.

    If issue persist then try to repair the Office Application if this option is available in MAC.

    Otherwise you can try to reinstall the Office Application to remove any kind of corruption.

    Then again try to make a same test to check whether it is working or not.

    Let me know about your testing result, If issue persist I will try to provide you further suggestions.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, March 15, 2018 8:52 AM
    Moderator
  • Hello Deepak,

    The only way to "fix" an Office installation in Mac is to reinstall it. As everything (including Outlook 2016) is working, I am reluctant to go ahead with such a big operation. 

    This site of Mr. Ron de Bruin has really great stuff on VBA, Excel and Mac: http://www.rondebruin.nl/mac/mail.htm . He has written AppleScript code to send mail from excel via Outlook, and I've tried it and it works!!!

    However, as I need to have an application that works both in a Windows PC as well as Mac, I cannot rely on the AppleScript. So, it would be best to find a solution within VBA or some other "common" language to use. 

    Mr. de Bruin points out that Outlook operates very differently from the other Office applications, and that in 2016 version, there are some serious drawbacks in the VBA in Mac. So, maybe this cannot be done, at all with VBA?

    I would just need to find an email in Outlook with a defined sender and heading, and then use the Excel attachment in that email to copy data to my summary Excel. Boy, how hard can this be...?


    • Edited by Juhta Friday, March 16, 2018 2:50 PM
    Friday, March 16, 2018 2:50 PM
  • Hi Juhta,

    I suggest you to refer link below which contains many examples that may solve your issue.

    Sending Mail from Excel 2011 by Using Apple Mail or Outlook 2011

    Below is one example from that link I posted here.

    Function MailFromMacwithOutlook(bodycontent As String, mailsubject As String, _
                toaddress As String, ccaddress As String, bccaddress As String, _
                attachment As String, displaymail As Boolean)
    
    
    
        Dim scriptToRun As String
    
        scriptToRun = scriptToRun & "tell application " & _
                      Chr(34) & "Microsoft Outlook" & Chr(34) & Chr(13)
    
        scriptToRun = scriptToRun & _
         "set NewMail to make new outgoing message with properties" & _
           "{content:""" & bodycontent & """, subject:""" & mailsubject & """}" & Chr(13)
    
        If toaddress <> "" Then scriptToRun = scriptToRun & _
           "make new to recipient at NewMail with properties" & _
           "{email address:{address:""" & toaddress & """}}" & Chr(13)
    
        If ccaddress <> "" Then scriptToRun = scriptToRun & _
           "make new cc recipient at NewMail with properties" & _
           "{email address:{address:""" & ccaddress & """}}" & Chr(13)
    
        If bccaddress <> "" Then scriptToRun = scriptToRun & _
           "make new bcc recipient at NewMail with properties" & _
           "{email address:{address:""" & bccaddress & """}}" & Chr(13)
    
        If attachment <> "" Then
         scriptToRun = scriptToRun & "make new attachment at NewMail with properties" & _
                  "{file:""" & attachment & """ as alias}" & Chr(13)
        End If
    
        If displaymail = False Then
            scriptToRun = scriptToRun & "send NewMail" & Chr(13)
        Else
            scriptToRun = scriptToRun & "open NewMail" & Chr(13)
        End If
        scriptToRun = scriptToRun & "end tell" & Chr(13)
    
        If Len(toaddress) + Len(ccaddress) + Len(bccaddress) = 0 Or mailsubject = "" Then
            MsgBox "There is no To, CC or BCC address or Subject for this mail"
            Exit Function
        Else
            On Error Resume Next
            MacScript (scriptToRun)
            On Error GoTo 0
        End If
    End Function
    
    Function MailFromMacWithMail(bodycontent As String, mailsubject As String, _
               toaddress As String, ccaddress As String, bccaddress As String, _
                    attachment As String, displaymail As Boolean)
    
    
    
        Dim scriptToRun As String
    
        scriptToRun = scriptToRun & "tell application " & _
                      Chr(34) & "Mail" & Chr(34) & Chr(13)
    
        scriptToRun = scriptToRun & _
             "set NewMail to make new outgoing message with properties " & _
                "{content:""" & bodycontent & """, subject:""" & _
                   mailsubject & """ , visible:true}" & Chr(13)
    
        scriptToRun = scriptToRun & "tell NewMail" & Chr(13)
    
        If toaddress <> "" Then scriptToRun = scriptToRun & _
           "make new to recipient at end of to recipients with properties " & _
           "{address:""" & toaddress & """}" & Chr(13)
    
        If ccaddress <> "" Then scriptToRun = scriptToRun & _
           "make new cc recipient at end of cc recipients with properties " & _
           "{address:""" & ccaddress & """}" & Chr(13)
    
        If bccaddress <> "" Then scriptToRun = scriptToRun & _
           "make new bcc recipient at end of bcc recipients with properties " & _
           "{address:""" & bccaddress & """}" & Chr(13)
    
        If attachment <> "" Then
            scriptToRun = scriptToRun & "tell content" & Chr(13)
            scriptToRun = scriptToRun & "make new attachment with properties " & _
                          "{file name:""" & attachment & """ as alias} " & _
                          "at after the last paragraph" & Chr(13)
            scriptToRun = scriptToRun & "end tell" & Chr(13)
        End If
    
        If displaymail = False Then scriptToRun = scriptToRun & "send" & Chr(13)
        scriptToRun = scriptToRun & "end tell" & Chr(13)
        scriptToRun = scriptToRun & "end tell"
    
        If Len(toaddress) + Len(ccaddress) + Len(bccaddress) = 0 Or mailsubject = "" Then
            MsgBox "There is no To, CC or BCC address or Subject for this mail"
            Exit Function
        Else
            On Error Resume Next
            MacScript (scriptToRun)
            On Error GoTo 0
        End If
    End Function
    
    Function KillFileOnMac(Filestr As String)
    
    
    'The VBA Kill command on a Mac will not work with long file names(28+ characters)
        Dim ScriptToKillFile As String
        ScriptToKillFile = ScriptToKillFile & "tell application " & Chr(34) & _
                           "Finder" & Chr(34) & Chr(13)
        ScriptToKillFile = ScriptToKillFile & _
                           "do shell script ""rm "" & quoted form of posix path of " & _
                           Chr(34) & Filestr & Chr(34) & Chr(13)
        ScriptToKillFile = ScriptToKillFile & "end tell"
    
        On Error Resume Next
        MacScript (ScriptToKillFile)
        On Error GoTo 0
    End Function

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, March 19, 2018 7:36 AM
    Moderator