如何在AddIns菜单(Excel VBA)中重新定位自定义命令按钮?

时间:2017-11-29 15:21:10

标签: excel vba excel-vba

我在excel功能区的AddIns菜单中创建了一个自定义命令按钮。问题是我的代码是在命令栏的左下角创建按钮(它正确地放在AddIns菜单中)。如何将命令按钮重新定位到AddIns菜单的左上角?

Private Sub Workbook_AddinInstall()
    Dim iContIndex As Integer
    On Error Resume Next 'Just in case

   'Delete any existing menu item that may have been left
    Application.CommandBars("Worksheet Menu Bar").Controls("Compare").Delete

    'Pass the Index of the "Format" menu item number to a Variable.
    iContIndex = Application.CommandBars.FindControl(ID:=30006).Index

    'Add the new menu item and Set a CommandBarButton Variable to it.
    'Use the number passed to our Integer Variable to position it.
    Set cControl = Application.CommandBars("Worksheet Menu Bar").Controls.Add(Before:=iContIndex)
    With cControl
        .FaceId = 585
        .Caption = "Compare"
        .Style = msoButtonIconAndCaption
        .OnAction = "CompareFS"
    End With

    On Error GoTo 0
End Sub

1 个答案:

答案 0 :(得分:1)

要控制功能区上的内容,您应该使用功能区自定义。 www.rondebruin.nl有关于自定义功能区的所有信息。