Link to home
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

ASKER CERTIFIED SOLUTION
Avatar of Emmanuel Adebayo
Emmanuel Adebayo
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Juan Velasquez

ASKER

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
Your answer put me on the right track