【问题标题】:Excel 2010 Ribbon Calling MacrosExcel 2010 功能区调用宏
【发布时间】:2015-06-09 12:16:46
【问题描述】:

我有一个 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 项目的 Module1 中的 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 执行此操作,也无法下载任何实用程序或其他程序。

提前致谢。

【问题讨论】:

    标签: excel excel-2010 ribbon vba


    【解决方案1】:

    如果您想保持理智,可以使用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

    【讨论】:

    • 不幸的是,我无法在工作中下载和安装东西,所以这一切都由我手动完成......谢谢,这正是我所需要的
    猜你喜欢
    • 2011-10-29
    • 1970-01-01
    • 1970-01-01
    • 2014-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多