【发布时间】:2016-07-08 17:43:36
【问题描述】:
我正在尝试让我的 Excel 插件在启用后将自定义按钮添加到功能区。该按钮应调用插件中保存的子程序。我正在使用自定义 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
【问题讨论】:
-
请分享您的宏,因为它的签名很重要...