Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a function that creates an email via VBA.

I made this through Excel 2016. When some of my colleagues try to use it there an error of missing references (Outlook Library 16.0).

I looked in the internet for solutions and found the best is Late Binding. I have read about it but I don't understand how to make it work in the following example code.

Sub EscalateCase(what_address As String, subject_line As String, email_body As String)
    
    Dim olApp As Outlook.Application
    Set olApp = CreateObject("Outlook.Application")
    
    Dim olMail As Outlook.MailItem
    Set olMail = olApp.CreateItem(olMailItem)
        
    olMail.To = what_address
    olMail.Subject = subject_line
    olMail.BodyFormat = olFormatHTML
    olMail.HTMLBody = email_body
    olMail.Send
        
End Sub
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
701 views
Welcome To Ask or Share your Answers For Others

1 Answer

This is early binding:

Dim olApp As Outlook.Application
Set olApp = New Outlook.Application

And this is late binding:

Dim olApp As Object
Set olApp = CreateObject("Outlook.Application")

Late binding does not require a reference to Outlook Library 16.0 whereas early binding does. However, note that late binding is a bit slower and you won't get intellisense for that object.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...