简体   繁体   English

VBA Excel - 以编程方式添加引用

[英]VBA Excel - Add references programmatically

I built a excel macro using the "Microsoft Outlook 15.0 Object Library" reference, but when I send the file to other people they get this error: " Can't find project or library ".我使用“Microsoft Outlook 15.0 对象库”参考构建了一个 excel 宏,但是当我将文件发送给其他人时,他们收到此错误:“找不到项目或库”。

This file will be used by a lot of people, so I have to add it from VBA Code.这个文件会被很多人使用,所以我必须从VBA代码中添加它。

I'm using this code that runs when you open the excel file, which is returning the following error: " Error in loading DLL "我正在使用当您打开 excel 文件时运行的此代码,该代码返回以下错误:“加载 DLL 时出错

Private Sub Workbook_Open()
       Application.VBE.ActiveVBProject.References.AddFromFile "C:\Program Files (x86)\Microsoft Office\Office15\MSOUTL.OLB\"
End Sub

Do you have any idea why this is happening?你知道为什么会这样吗?

Thanks谢谢

If you still want to keep the early binding you could use the GUID in order to add the libray, ie如果您仍然想保留早期绑定,您可以使用 GUID 来添加库,即

Sub AddOL_Ref()

Application.VBE.ActiveVBProject.REFERENCES. _
    AddFromGuid "{00062FFF-0000-0000-C000-000000000046}", 1, 0

End Sub

Advantage of using the GUID is that it is constant and does not change with the version of the program.使用 GUID 的优点是它是不变的,不会随着程序的版本而改变。

Here one finds an extened discussion on dis/advantages of early resp. 在这里可以找到关于早期响应的缺点/优点的扩展讨论。 late binding.后期绑定。

You will have to remove the references & use late binding您将不得不删除引用并使用后期绑定

or you can also try this.或者你也可以试试这个。 Send your code to one of the user having 2010MS.将您的代码发送给拥有 2010MS 的用户之一。

Goto VBA > Tools > References转到 VBA > 工具 > 参考

Check for any missing references.检查是否有任何缺失的参考文献。 You may have Microsoft Outlook 15.0 Object Library showing as missing.您可能有Microsoft Outlook 15.0 对象库显示为丢失。 Un-check this, browse down and select Microsoft Outlook 14.0 Object Library .取消选中此项,向下浏览并选择Microsoft Outlook 14.0 Object Library

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM