简体   繁体   English

从普通Excel工作簿(.xlsx)上单击按钮时触发外部宏

[英]Triggering external macro on button click from normal excel workbook (.xlsx)

Stated simply my question is as follows Is it possible for a button on a worksheet in a normal excel workbook (.xlsx not .xlsm) to trigger a macro in another file specifically an installed excel add in (.xlam). 简而言之,我的问题如下:正常的excel工作簿中的工作表上的按钮(.xlsx不是.xlsm)是否可以触发另一个文件中的宏,特别是已安装的excel加载项(.xlam)。

Here is some background on why I want to achieve this. 这是我为什么要实现这一目标的一些背景。 I have a workbook that many users need to be able to view but only some need to be able to update by filling in a form on another sheet and calling a macro in an add in. The worksheet should not contain any macros to avoid security warnings when opened by normal users. 我有一本工作簿,许多用户需要能够查看,但只有一些用户需要通过在另一张纸上填写表格并在外接程序中调用宏来进行更新。该工作表不应包含任何宏,以避免安全警告由普通用户打开时。 I can do this by having a ribbon button in the add in that the user clicks which will then check that the correct workbook is open and that the form is filled in etc. before executing the update code. 我可以通过在添加项中具有一个功能区按钮来执行此操作,用户单击该按钮,然后在执行更新代码之前将检查是否打开了正确的工作簿以及是否已填写表格等。 However the interface would be nicer if the button instead of appearing on the ribbon was on the worksheet just below the form. 但是,如果按钮(而不是显示在功能区上)位于表单下方的工作表上,则界面会更好。 Therefore my question is it possible to trigger an external macro from a button click in a non macro enabled workbook. 因此,我的问题是是否可以通过在未启用宏的工作簿中单击按钮来触发外部宏。

Yes, you can assign an external macro (which should be .xlsm file) to a non-macro-enabled workbook ( .xlsx) button. 是的,您可以将外部宏(应为.xlsm文件)分配给未启用宏的工作簿( .xlsx)按钮。 My xlsm macro resides in the same directory as the xlsx workbook for simplicity. 为简单起见,我的xlsm宏与xlsx工作簿位于同一目录中。 (Note: I am using Excel 2010) (注意:我正在使用Excel 2010)

  1. Firstly, you must open your xlsm macro in the same instance of Excel window (ie do not open a new instance of Excel) so that your xlsx workbook will be able to see/access it. 首先,必须在同一Excel窗口实例中打开xlsm宏(即,不要打开Excel的新实例),以便您的xlsx工作簿能够看到/访问它。
  2. Right-click on your xlsx workbook button and select "Assign Macro..." 右键单击您的xlsx工作簿按钮,然后选择“分配宏...”
  3. Make sure you select Macros in: All Open Workbooks 请确保您在:所有打开的工作簿中选择宏
  4. All macros in open workbooks will be shown (this is why it is important to do step 1). 将显示打开的工作簿中的所有宏(这就是为什么执行第1步很重要)的原因。
  5. Select the desired macro from the list then click OK. 从列表中选择所需的宏,然后单击“确定”。

我看不到如何从未启用宏的工作簿中的控件执行宏。

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

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