vba 如何在打开 Excel 工作簿时自动打开加载项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19200095/
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
How to open add-in automatically on opening excel workbook
提问by MiniMite
I want to know how can i have a workbook automatically open an add-in? the problem is create the workbook in code call it "A.xlsx" now i want to add code to it (on creation) that will open the excel add-in "B.xlam". how do i do this? creating the workbook is no problem< that part is sorted, i just want to add the code to that workbook, so that everytime it opens it must open the add-in "B.xlam" with it.
我想知道如何让工作簿自动打开加载项?问题是在代码中创建工作簿,将其称为“A.xlsx”,现在我想向其中添加代码(在创建时),这将打开 excel 加载项“B.xlam”。我该怎么做呢?创建工作簿没问题<该部分已排序,我只想将代码添加到该工作簿中,以便每次打开它时都必须使用它打开加载项“B.xlam”。
回答by David Zemens
From the Developer Ribbon, click Add-Ins,
从开发人员功能区中,单击加载项,
then click Browse, then navigate to the location of the desired add-in file, then select it, and make sure the checkbox is selected for it.
然后单击浏览,然后导航到所需加载项文件的位置,然后选择它,并确保为其选中复选框。
Alternatively, store the code in PERSONAL.XLS/PERSONAL.XLSB, and these macros/functions will be available to all open workbooks.
或者,将代码存储在 PERSONAL.XLS/PERSONAL.XLSB 中,这些宏/函数将可用于所有打开的工作簿。
If you're somehow asking how to programmatically insert code in to new workbook files, I'm afraid you're out of your element. If you don't know about the Workbook_Open
event, nor how to manage your Add-Ins, etc., manipulating the VBE is a pretty high-level operation, and I would not be able to help you with that.
如果您以某种方式询问如何以编程方式将代码插入到新的工作簿文件中,恐怕您已经超出了您的要求。如果您不了解该Workbook_Open
事件,也不了解如何管理您的加载项等,那么操作 VBE 是一项非常高级的操作,我将无法为您提供帮助。
Update from comments
从评论更新
Here is one method that will export VB Components to a specific path, example also includes code to import modules from path to a workbook. You should be able to adapt this to your purposes.
这是将 VB 组件导出到特定路径的一种方法,示例还包括将模块从路径导入到工作簿的代码。您应该能够根据您的目的进行调整。
http://www.rondebruin.nl/win/s9/win002.htm
http://www.rondebruin.nl/win/s9/win002.htm
If you have specific problems implementing this solution, please post as a new question.
如果您在实施此解决方案时遇到具体问题,请将其作为新问题发布。