从功能区调用一个excel宏 [英] Calling an excel macro from the ribbon
问题描述
简介:
我已经编写了一些简短的excel宏(经测试,他们工作正常),并希望将它们链接到功能区(Excel 2010)中的按钮。我已经在Excel 2007中成功完成了。
我正在使用自定义UI编辑器构建一个新的功能区,这也可以正常工作。一切都包装在.xlam加载项中,并添加到Excel中。色带显示得很好,所有其他按钮都有效,但... ...
问题:
当我点击链接到宏的按钮我得到错误:错误的参数数量或属性分配无效(从意大利语翻译的消息可能与英文不一致)
疑难解答信息:
宏没有参数。可以手动成功调用和执行相同的宏。我甚至可以将相同的宏添加到快速访问工具栏。
以下是功能区脚本的具体部分:
< group id =DupNumberlabel =NumberinsertBeforeMso =GroupNumber>
< comboBox idMso =NumberFormatGallery/>
< box id =HN1boxStyle =horizontal>
< buttonGroup id =HNButtonGroup1>
< button id =EuroonAction =Roberto.xlam!EURZimageMso =Fsupertip =text .../>
< button id =EuroNZonAction =Roberto.xlam!EURNZimageMso =Esupertip =text .../>
< button idMso =PercentStyle/>
< button id =CommaonAction =Roberto.xlam!NewCommaFormatimageMso =Csupertip =test .../>
< button idMso =PercentStyle/>
< / buttonGroup>
< / box>
这里是宏:
Sub EURZ()
Application.ActiveCell.NumberFormat =€#,## 0.00
End Sub
Sub EURNZ()
应用程序.ActiveCell.NumberFormat =€#,## 0
End Sub
Sub NewCommaFormat()
Application.ActiveCell.NumberFormat =#,## 0
End Sub
你能帮我吗?
感谢
Roberto
Roberto
我相信你需要添加这个参数到你的宏控制作为IRibbonControl
所以应该看起来像这样:
Sub EURZ(控制为IRibbonControl)
Application.ActiveCell.NumberFormat =€#,## 0.00
End Sub
<
-Justin
>
Intro:
I have written some short excel macros (tested, they work fine) and want to link them to a button in the Ribbon (Excel 2010). I had already done it successfully in Excel 2007.
I am using Custom UI Editor to build a new ribbon, which also works fine. Everything is packaged in a .xlam add-in and added to Excel. The ribbon shows up nicely, all other buttons works, but ...
Problem:
when I hit the button that is linked to the macro I get the error: "wrong number of parameters or property assignment not valid" (message translated from Italian, might not be exactly the same in English)
Troubleshooting info:
The macros do not have parameters. The same macros can be successfully called and executed manually. I am even able to add the same macros to the Quick Access Toolbar.
Here is the specific portion of the ribbon script:
<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>
and here are the macros:
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
Can you help me?
Thanks
Roberto
解决方案 Roberto,
I believe you need to add this param to your macro "control As IRibbonControl"
So it should look like this:
Sub EURZ(control As IRibbonControl)
Application.ActiveCell.NumberFormat = "€ #,##0.00"
End Sub
Hope that works for you.
-Justin
这篇关于从功能区调用一个excel宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!