I'm creating a custom command button in the AddIns menu in my excel ribbon. The issue is that my code is creating the button in the bottom left corner of the commandbar (it is correctly being put in the AddIns menu). How can I reposition my command button to be in the top left corner of my AddIns menu?
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
TO have control over where things go on the ribbon you should be using Ribbon customisation. www.rondebruin.nl has all you need to know about customising the ribbon.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.