【问题标题】:Automatically refresh imported macros in excelexcel自动刷新导入的宏
【发布时间】:2017-03-10 17:32:36
【问题描述】:

我目前正在更新多个单独的 Excel 文档以使用宏。

虽然这些文档中的每一个都是独立的,但它们之间却共享了许多方程式。为了让我的生活更轻松,我将宏导出到 bas 文件中,然后将其导入到每个后续文件中。我目前遇到的问题是,有时需要更改或更新其中一些方程式。这目前导致我必须转到每个 excel 文件,删除以前导入的 bas 文件并重新导入新文件。有没有办法通过某种形式的符号链接导入 bas 文件或强制 Excel 检查文件的位置并确保 bas 文件是最新的。

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

文档 1 有一个方程 宏: 等式 1:(value1 + value2) / value1

这是导出到macros.bas

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

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

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

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

有没有办法自动化步骤 2 - 3,通过符号链接或强制 excel 自动刷新从 macros.bas 导入的宏?

感谢您的回复。

【问题讨论】:

  • 听起来好像您应该使用加载项来存储共享代码,而不是将其放入每个工作簿中。这样你只需要在一个地方更新代码。
  • 谢谢。完成后我会调查并发布我的解决方案。
  • 我之前遇到过这个问题 - 我所做的是将调用宏的工作簿分发到我控制的集中式工作簿中,因此无论他们多久之前收到工作簿,它都会保持最新状态因为它会调用我可以管理的宏。这并不能解决手头的问题,但可以阻止它再次发生!

标签: excel vba


【解决方案1】:

正如 Rory 所建议的,这个问题的答案在于插件的使用 感谢以下堆栈溢出文章的指导。 running a macro from an add-in

这是我最终执行的解决方案。

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

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.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-16
    • 2015-10-28
    • 2016-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多