Reputation: 3236
I have a plugin for Word. On office for windows it is able to show a customised ribbon using ribbon XML. On office 2011 for mac, it ignores this ribbon but I am able to add a CommandBar (A dropdown menu at the top). These allow me to create a menu system for my various macros.
In Office 2016, when I try to create a commandbar I get the error: "Method 'Add' of Object 'CommandBarControls' failed
. It also does not allow custom ribbons, it doesn't pick up the XML which is in the dotm file (Neither does it seem to let me manually change the ribbon).
This leads me to the question - Is there any way, any way at all, that I can add some buttons somewhere to fire macros on this version of office? Preferably something I can create using VBA (Currently the commandbars are added from VBA).
Since this works in Office for Windows (preview) as well as old versions of office for windows, as well as Office 2011 for mac - why wouldn't this work here?
For reference, here is my test code for creating a commandbar, pulled from http://scriptorium.serve-it.nl/view.php?sid=14
Sub CreateCommandBar()
Dim myCB As CommandBar
Dim myCBtn1 As CommandBarButton
Dim myCBtn2 As CommandBarButton
Dim myCPup1 As CommandBarPopup
Dim myCPup2 As CommandBarPopup
Dim myCP1Btn1 As CommandBarButton
Dim myCP1Btn2 As CommandBarButton
' Delete the commandbar if it exists already
' On Error Resume Next
Application.CommandBars("example").Delete
' Create a new Command Bar
Set myCB = CommandBars.Add(Name:="example", Position:=msoBarFloating)
' Add button 1 to this bar
Set myCBtn1 = myCB.Controls.Add(Type:=msoControlButton)
With myCBtn1
.Caption = "1st level Cap."
.Style = msoButtonCaption '<- will force the caption text to show on your button
End With
' Add popup menu 1 to this bar
Set myCPup1 = myCB.Controls.Add(Type:=msoControlPopup)
myCPup1.Caption = "Statistic"
' Add button 1 to popup menu 1
Set myCP1Btn1 = myCPup1.Controls.Add(Type:=msoControlButton)
With myCP1Btn1
.Style = msoButtonAutomatic
.FaceId = 487
End With
' Add button 2 to popup menu 1
Set myCP1Btn1 = myCPup1.Controls.Add(Type:=msoControlButton)
With myCP1Btn1
.Caption = "Click me!"
.Style = msoButtonIconAndCaption
.FaceId = 59
.OnAction = "SubItworks"
End With
' Add a second button to this bar
Set myCBtn2 = myCB.Controls.Add(Type:=msoControlButton)
With myCBtn2
.FaceId = 17 ' <- Face Id 17 is a barchart icon
.Caption = "Descriptive stat"
End With
' Show the command bar
myCB.Visible = True
End Sub
Sub SubItworks()
MsgBox ("Eureka, it works!")
End Sub
Upvotes: 3
Views: 2536
Reputation: 3236
Office 2016 for Mac now supports Ribbon XML customization. Currently experimental/opt-in, but will be enabled by default "in early 2016"
Upvotes: 0
Reputation: 46
Create a new .dotm file in Word 2011, run the CreateCommandBar() macro and then copy the toolbar (using the organizer dialog) and SubItworks() macro to the .dotm file. Put the .dotm file in Word 2016's startup folder and you'll see the toolbar in the ribbon's Add-in tab.
It's buggy though - the only controls that seems to work are top level buttons. Clicking on the popup button doesn't display a menu, and even the top level buttons aren't drawing properly when you click on them.
I've had better luck manually creating a new toolbar in Word 2011 (View:Toolbars:Customize Toolbars and Menus…) and then creating buttons by dragging macros to the toolbar. You can also manually set button properties using Visual Basic's locals window once you get a reference to the toolbar.
Buttons created that way seem to behave properly as long as you don't change any button properties at runtime.
Upvotes: 2