从功能区调用Excel宏

3
介绍: 我编写了一些简短的Excel宏(经过测试,可以正常工作),希望将它们链接到功能区(Excel 2010)中的按钮上。我已经在Excel 2007中成功完成了此操作。我正在使用Custom UI Editor构建一个新的功能区,这也很好地运行。所有内容都被打包在.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

你能帮助我吗? 谢谢 Roberto

1个回答

12

我认为你需要在宏中添加这个参数:control As IRibbonControl

所以它应该是这样的:

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

3
您可能还希望将此参数设置为可选,这样您就可以例如从调试器中继续运行子程序。 - Thierry Dalon
1
@Thierry Dalon 即使该参数被标记为可选,我仍然无法在宏列表下看到该子程序。不过,我可以通过功能区激活该子程序。 - TechFanDan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接