【问题标题】:Calling an excel macro from the ribbon从功能区调用 excel 宏
【发布时间】:2011-10-29 18:24:54
【问题描述】:

简介: 我编写了一些简短的 excel 宏(经过测试,它们工作正常),并希望将它们链接到功能区中的按钮(Excel 2010)。我已经在 Excel 2007 中成功完成了。 我正在使用自定义 UI 编辑器来构建一个新的功能区,它也可以正常工作。一切都打包在 .xlam 加载项中并添加到 Excel。功能区显示得很好,所有其他按钮都可以使用,但是...

问题: 当我点击链接到宏的按钮时,我收到错误消息:“参数数量错误或属性分配无效”(从意大利语翻译的消息,英文可能不完全相同)

疑难解答信息: 宏没有参数。可以手动成功调用和执行相同的宏。我什至可以将相同的宏添加到快速访问工具栏。

这是功能区脚本的具体部分:

<group id="DupNumber" label="Number" insertBeforeMso="GroupNumber" >  
    <comboBox idMso="NumberFormatGallery"/> 
    <box id="HN1" boxStyle="horizontal"> 
        <buttonGroup id="HNButtonGroup1"> 
            <button id="Euro" onAction="Roberto.xlam!EURZ" imageMso="F" supertip="text ..."/> 
            <button id="EuroNZ" onAction="Roberto.xlam!EURNZ" imageMso="E" supertip="text ..."/> 
            <button idMso="PercentStyle"/> 
            <button id="Comma" onAction="Roberto.xlam!NewCommaFormat" imageMso="C" supertip="test ..."/> 
            <button idMso="PercentStyle"/> 
        </buttonGroup> 
    </box>

这里是宏:

Sub EURZ()
    Application.ActiveCell.NumberFormat = "€ #,##0.00"
End Sub
Sub EURNZ()
    Application.ActiveCell.NumberFormat = "€ #,##0"
End Sub
Sub NewCommaFormat()
    Application.ActiveCell.NumberFormat = "#,##0"
End Sub

你能帮帮我吗? 谢谢 罗伯托

【问题讨论】:

    标签: excel ribbon


    【解决方案1】:

    我相信您需要将此参数添加到您的宏中:control As IRibbonControl

    所以它应该是这样的:

    Sub EURZ(control As IRibbonControl)
        Application.ActiveCell.NumberFormat = "€ #,##0.00"
    End Sub
    

    【讨论】:

    • 您可能还想将此参数设置为可选,以便您可以继续从调试器运行子程序。
    • @Thierry Dalon 即使参数被标记为可选,我也不再看到宏列表下的 Sub。不过,我可以通过功能区激活 Sub。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多