更新Microsoft 2010 VBA对象库 [英] Updating Microsoft 2010 VBA Object Libraries
问题描述
我在运行Microsoft Office 2016的工作计算机上创建了一个程序,但是,我的同事无法使用VBA程序,因为它没有更新的对象库.具体来说,日期和左功能会阻止程序运行.
I created a program on my work computer which runs Microsoft Office 2016 however, my colleague cannot use the VBA program because it doesn't have the updated object library. Specifically, the Date and Left function prevent the program from working.
如果他们运行的是Microsoft Office 2010版本,是否可以更新其对象库?
If they are running a 2010 version of Microsoft Office, is it possible to update their Object Libraries?
推荐答案
您不能使用使用较旧版本的较新版本的引用,因为它可以提供较旧版本没有的功能,反之亦然它可以正常工作(旧引用带有新库,因为它们通常是向后兼容的.)
You can't use references to newer libary version using an older version as it can provide functions that the older version don't have, just the other way around it could work (old reference with new libary as they are usually backward compatible).
如果一个引用损坏,则其他所有引用也不会加载.这就是VBA
函数Date
和Left
失败的原因,因为未加载库.
If one reference is broken, all other are not loaded too. That's why the VBA
functions Date
and Left
fail as the libary is not loaded.
要独立于Office
版本,请使用后期绑定,但即使如此,您也不能在旧版本上使用新功能(只需使用要支持的最旧版本的子集或检查版本,以及是否如果版本太旧,则会显示一条消息,说明此功能Office
版本不支持使用该功能的功能.
To get independent of the Office
version use Late-Binding, but even then you can't use new functions on old versions (just use the subset of the oldest version you want to support or check for version and if the it is too old display a message that the faeture that uses the function is not availible for this Office
version).
您可以开发Early-Bound
以具有Intellisense
和对象浏览器,并在分发之前切换到Late-Bound
.
You can develop Early-Bound
to have Intellisense
and object browser and switch to Late-Bound
before distributing.
- 在VBA中删除参考->工具
- 将类声明更改为
Object
- 使用
CreateObject
创建实例
- 用自己的枚举,整数值或常量替换枚举
- Remove the reference(s) in VBA -> Tools
- Change class declarations to
Object
- Create instance with
CreateObject
- Replace enums with your own enum, with their integer value or with a constant
示例:
Dim OutlookInstance as Outlook.Application
Dim OlMailItem as Outlook.Mailitem
Set OutlookInstance = New Outlook.Application
Set OlMailItem = OutlookInstance.CreateItem(olMailItem)
更改为:
Dim OutlookInstance as Object
Dim OlMailItem as Object
Set OutlookInstance = CreateObject("Outlook.Application")
Set OlMailItem = OutlookInstance.CreateItem(0)
You can download a module with enums for Outlook 2013
at Codekabinet (not tested, but they should cover most of Outlook 2016
) and import to your project or get the values while you are Early-Bound
from object-browser or just google.
这篇关于更新Microsoft 2010 VBA对象库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!