如何在 vba 中添加库引用,以便每次打开新工作簿时都保持添加状态?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14985291/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 19:43:02  来源:igfitidea点击:

How do I add a library reference in vba so that it remains added every time I open a new workbook?

excelvbaexcel-vba

提问by Ben G

Forgive me, I'm still sort of new to this, but...

原谅我,我对这个还是有点陌生​​,但是......

In vba within Excel, when I go to Tools - References I can add a reference and it works just fine. The box stays checked everytime I reopen that workbook.

在 Excel 中的 vba 中,当我转到“工具”-“参考”时,我可以添加一个参考,并且效果很好。每次我重新打开该工作簿时,该框都会保持选中状态。

However, if I create a new workbook, I have to re-establish the reference to that same library. How do I set this up so that the library reference I want remains checked all the time - at an Excel Application level as opposed to an Excel Workbook level? Thanks

但是,如果我创建一个新的工作簿,我必须重新建立对同一个库的引用。我如何设置它以便我想要的库引用始终保持检查 - 在 Excel 应用程序级别而不是 Excel 工作簿级别?谢谢

采纳答案by Siddharth Rout

Follow thesesteps to Create a personal workbook.

按照以下步骤创建个人工作簿。

Once you have created the workbook. Simply go to the VBA editor of the personal workbook and add the reference. Close all workbooks and now open a new one. You will see that the reference is already there.

创建工作簿后。只需转到个人工作簿的 VBA 编辑器并添加引用即可。关闭所有工作簿,现在打开一个新的。您将看到引用已经存在。

In case the above link ever breaks. Here is a screenshot of that link.

以防上述链接中断。这是该链接的屏幕截图。

enter image description here

在此处输入图片说明

回答by Michael Fayad

I had the same problem. My solution was to use late binding instead of early bindingfor my outlook objects setting. With late binding, my code became agnostic of the outlook reference libraries. Thus, the code could easily be used on any computer without checking the referenced libraries. This is much more convivial for making macros for unsavvy users.

我有同样的问题。我的解决方案是对我的 Outlook 对象设置使用后期绑定而不是早期绑定。由于后期绑定,我的代码变得与 Outlook 参考库无关。因此,该代码可以轻松地在任何计算机上使用,而无需检查引用的库。这对于为不精明的用户制作宏更加愉快。