Excel 2010 功能区调用宏

Excel 2010 Ribbon Calling Macros

我有一个 Excel 加载项(.xlam 文件),其中有一些宏和我在自定义功能区选项卡上的尝试。宏按预期工作,但现在我正在尝试制作功能区以调用它们以更加用户友好。我有功能区和一个可以使用的按钮,以及一个我无法弄清楚的下拉菜单。我不确定宏参数需要是什么。以下是我到目前为止的内容。

色带的 XML(有效!):

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
  <ribbon>
    <tabs>
      <tab id="My_Tab" label="My Tab">
        <group id="NC_Material" label="Button1">
          <button id="Button1" label="1st button" size="large" onAction="Module1.Button1Click" imageMso="ResultsPaneStartFindAndReplace" />
          <dropDown id="DropDown" onAction="Module1.DropDownAction">
            <item id="ddmItem1" label="Item1" />
            <item id="ddmItem2" label="Item2" />
          </dropDown>
        </group >
      </tab>
    </tabs>
  </ribbon>
</customUI>

.xlam 文件 VBA 模块 1 中的 VBA 项目:

'this one works
Public Sub Button1Click(ByVal control As IRibbonControl)
    call Button1Macro
End Sub

'this one does not work
Public Sub DropDownAction(ByVal control As IRibbonControl)
    call DropDownMacro
End Sub

当我更改功能区中下拉菜单的值时出现错误。我不知道下拉菜单的 onAction 宏需要什么参数。我一直找不到很好的参考或例子。

我无法使用 Visual Studio 执行此操作,也无法下载任何实用程序或其他程序。

提前致谢。

如果您想保持理智,可以使用 Andy Pope's Ribbon Editor,它会自动生成回调(至少是它们的文本)。然后你只需将它们复制到 VBA 模块中。 (我与该插件无关,我只是使用它并强烈推荐它)

使用该工具,我在 Dropdown

中得到 onAction 的以下结果
Public Sub DropDownAction(control as IRibbonControl, id as String, index as Integer)
'
' Code for onAction callback. Ribbon control dropDown
'

End Sub

还显示了工作代码 in this answer,它在我搜索的顶部附近。