我正在尝试让Excel Addin在启用时为功能区添加自定义按钮。该按钮应调用addin中保存的子。我正在使用自定义UI编辑器并按照此处列出的方法http://www.rondebruin.nl/win/s2/win001.htm。它已经创建了按钮,但是当我单击按钮时它不会调用宏。它给出了“错误的参数数量或无效的属性赋值”的错误。宏本身正常工作,所以我认为这是我写按钮的问题。关于我做错了什么的任何想法?下面的代码是UI编辑器中的内容。
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<ribbon>
<tabs>
<tab idMso="TabHome" >
<group id="customGroup1" label="My Group" insertAfterMso="GroupEditingExcel">
<button id="customButton1" label="Delete Totals" size="large"
onAction="DeleteBoldTotals" imageMso="HappyFace" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
我尝试过的另一种变体,因为某些原因按钮甚至没有显示出来;
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<ribbon>
<tabs>
<tab idMso="TabHome" >
<group id="customGroup1" label="My Group" insertAfterMso="GroupEditingExcel">
<button id="customButton1" label="Delete Totals" size="large"
onAction=Application.Run "DeleteBoldTotals" imageMso="InkEraseMode" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
我需要它调用的宏是:
Option Explicit
Sub DeleteBoldTotals()
Dim vFIND As Range, vFIRST As Range, delRNG As Range
Dim ws As Worksheet
On Error Resume Next
For Each ws In ActiveWorkbook.Worksheets
Set vFIND = ws.Cells.Find("Total", LookIn:=xlValues, LookAt:=xlPart)
If Not vFIND Is Nothing Then
Set vFIRST = vFIND
Do
If vFIND.Font.Bold = True Then
If delRNG Is Nothing Then Set delRNG = vFIND Else Set delRNG = Union(delRNG, vFIND)
End If
Set vFIND = ws.Cells.FindNext(vFIND)
Loop Until vFIND.Address = vFIRST.Address
If Not delRNG Is Nothing Then
delRNG.EntireRow.Delete xlShiftUp
End If
Set vFIND = Nothing
Set vFIRST = Nothing
Set delRNG = Nothing
End If
Next ws
End Sub
答案 0 :(得分:3)
第一个是正确的。在您需要放置的子名称中:
Sub name(rib as iRibbonControl)