如何在VBA中进行后期绑定? [英] How to do late binding in VBA?

查看:965
本文介绍了如何在VBA中进行后期绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个小功能,可以通过VBA创建电子邮件,
它从与Excel文件一起使用的另一个函数中获取数据.

I have this little function that achieves the creation of an email via VBA,
It gets the data from another function that works together with an Excel file.

我遇到的问题是,我通过Excel 2016进行了所有这些工作,并且当我的一些同事尝试使用它时,出现了缺少引用的错误(Outlook Library 16.0).

The problem I have is that I made all this thru Excel 2016, and when some of my colleagues try to use it there an error of missing references (Outlook Library 16.0).

因此,我查看了Internet解决方案,发现了很多解决方案,但是后期绑定"更好.我已经阅读了所有内容,但似乎不太了解正在发生的事情以及如何在以下代码中使它工作.

So I looked in the internet solutions and the ones I found are many, but the better is Late Binding. I have read all about it but I don't seem to really understand what's going on and how to make it work in the following 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

因此,也许您可​​以帮我看一下这个例子,以了解我的实际情况.

Therfore, maybe you can help me out with this example in order to see it this practical case of mine.

推荐答案

这是早期绑定:

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

这是后期绑定:

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

后期绑定不需要引用 Outlook Library 16.0 ,而早期绑定则需要引用.但是,请注意,后期绑定要慢一些,并且您不会对该对象有任何智能感知.

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.

这篇关于如何在VBA中进行后期绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆