Avatar of Juan Velasquez
Juan VelasquezFlag for United States of America asked on

Getting Missing: Microsoft Outlook 14.0 Library on user's machine

Hello,

I am getting the following reference error when a user is trying to send a email from Excel via automation.  The problem is that I am used late binding in writing the email code.  So why am I still getting that error

Getting Missing: Microsoft Outlook 14.0 Library on user's machine

How
' Module     : basSendMail
' Description:
' Procedures : SendMail(strRecipients As String, strCC As String, strBCC As String, strSubject As String, strTextBody As String, strHTMLBody As String, strAttachments As String, Optional eOlImportance As Integer = 1, Optional fDisplay As Boolean = True) As Boolean
' Modified   :
' 08/16/13 JV Cleaned with Total Visual CodeTools
'
' --------------------------------------------------
Option Explicit

Public Function SendMail(strRecipients As String, strCC As String, strBCC As String, strSubject As String, strTextBody As String, strHTMLBody As String, strAttachments As String, Optional eOlImportance As Integer = 1, Optional fDisplay As Boolean = True) As Boolean
    ' Comments: Sends a message using the following properties : Recipients, CC, BCC, SubjectBody, Delimiter
    ' Params  : strRecipients       List of recipients (TO address)
    '           strCC               List of carbon copy (CC) recipients
    '           strBCC              List of blind carbon copy (BCC) recipients
    '           strSubject          Subject of email
    '           strTextBody         Text Body of email, if any
    '           strHTMLBody         HTML body of email, if any
    '           strAttachments      List of attachment files (separated with the delimiter character which defaults to ;)
    '           eOIImportance       Importance of the email (defaults to olImportanceNormal, can also be olImportanceHigh, olImportanceLow)
    '           fDisplay            True to display the Mail Dialog, False otherwise. Default value is False.
    ' Returns : True if sent, False if failed
    ' Source  : Total Visual SourceBook
    
    On Error GoTo PROC_ERR
    
    Dim astrTmpAttachments() As String
    Dim intCount As Integer
    Dim strM_strDelimiter As String
    Dim objOOutlook As Object
    Dim objOutMailItem As Object
    Dim objOutAttachments As Object
    
    strM_strDelimiter = ","
    
    Set objOOutlook = CreateObject("Outlook.Application")
    ' Assume failure
    SendMail = False
    
    ' Create new instance of Outlook MailItem Object for you to work with.
    Set objOutMailItem = objOOutlook.CreateItem(0)          'You must use 0 instead of olMailItem with late-binding
    
    With objOutMailItem
        .To = strRecipients
        .CC = strCC
        .BCC = strBCC
        .Subject = strSubject
        .Body = strTextBody
        If strHTMLBody <> "" Then
            .HTMLBody = strHTMLBody
            .BodyFormat = 2   'olFormatHTML
        Else
            .BodyFormat = 1   'olFormatPlain
        End If
        .Importance = eOlImportance
        
        ' Parse Attachments and Add them to the Attachments Collection
        If strAttachments <> "" Then
            Set objOutAttachments = .Attachments
            astrTmpAttachments = Split(strAttachments, strM_strDelimiter)
            For intCount = 0 To UBound(astrTmpAttachments)
                objOutAttachments.Add astrTmpAttachments(intCount), 1  'olByValue
            Next intCount
        End If
        If fDisplay Then
            .Display
        End If
        
        .Send
        
    End With
    
    SendMail = True
    
PROC_EXIT:
    Exit Function
    
PROC_ERR:
    MsgBox "Error: " & Err.Number & ". " & Err.Description, , "COutlookMail.SendMail"
    Resume PROC_EXIT
End Function

Open in new window

Outlook

Avatar of undefined
Last Comment
Juan Velasquez

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Emmanuel Adebayo

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
Juan Velasquez

I found the problem.  I had inadvertently checked the Microsoft Outlook 14.0 Object Library  before I distributed it .  Consequently,  when an Excel 2007 user opened the application, he received a error message.  Since I'm using late binding, I unchecked the Microsoft Outlook Object library reference, and everything is working fine
ASKER
Juan Velasquez

Your answer put me on the right track
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck