在Excel中自动刷新导入的macros

我目前正在更新多个单独的Excel文件使用macros。

尽pipe这些文件中的每一个都是分开的,但是它们之间有许多等式。 为了使我的生活更轻松,我已经将我的macros导出到一个bas文件,然后导入到每个后续文件中。 我目前遇到的问题是偶尔需要更改或更新这些等式中的一些。 这个现在导致我不得不去每个excel文件,删除以前导入的bas文件并重新导入新的。 有没有办法通过某种forms的符号链接导入bas文件,或强制Excel检查文件的位置,并确保bas文件是最新的。

下面是一个简单的用例,因为我可能在我的ramblings中不太清楚:

文档1有一个等式macros:等式1:(值1 +值2)/值1

这被导出到macros.bas

文档2使用相同的macros,因此只需导入macros.bas:公式1:(value1 + value2)/ value1

两天后,我被告知,方程应该被修改,使方程除以值2。 为此,执行以下步骤。

步骤1)更新bas文件,使得公式1:(value1 + value2)/ value2

步骤2)打开文档1和文档2步骤3)我必须删除旧的macros模块并重新导入新的模块。

有没有一种方法来自动化步骤2 – 3,通过符号链接或强制Excel从macros.bas自动刷新导入的macros?

谢谢你的回应。

正如Rory所build议的那样,这个问题的答案在于使用Add-Ins Kudos来指导下面的堆栈溢出文章。 从加载项运行macros

这是我最终完成的解决scheme。

创build一个全新的工作簿。 这将存储所有需要共享的模块。

1 - In the Developer tab select Visual Basic. 2 - Create the module/modules I want to store my macros in and start writing them. 3 - Save the Workbook selecting the type "Excel Add-In (*.xlam)" 4 - Open the Workbook I wish to actually work on. 5 - File -> Options. Select the Add-Ins tab (Or go to Developer tab -> Add-Ins) 6 - At the bottom under "Manage" ensure "Excel Add-Ins" is selected in the combo box and select Go 7 - Browse... and find the .xlam file you just saved. 8 - The macros should now be loaded. You can test them out in a cell or go to Developer -> Visual Basic. In the Visual Basic Project panel on the left of the new window, your Add-In should appear along with your current workbook. 9 - You may be required to restart Excel before using the Add-In Macros. 

额外的注意事项:删除不需要的加载项(假设你是新来的,因为我是)

 1 - File -> Options. Select the Add-Ins tab 2 - At the bottom under "Manage" ensure "Excel Add-Ins" is selected in the combo box and select Go 3 - Uncheck the Add-In you wish to remove. Going to the Developers tab -> Visual Basic should now display that the Add-In has been removed from the project.