Word 2016 for mac - any custom controls

I have a plugin for Word. In office for windows, it can display a custom ribbon using ribbon XML. In Office 2011 for mac, it ignores this ribbon, but I can add a CommandBar (dropdown at the top). This allows me to create a menu system for my various macros.

In Office 2016, when I try to create a command line, I get the following error: "Method 'Add' of Object 'CommandBarControls' failed

. It also doesn't let you create custom feeds, it doesn't pick up the XML that's in the dotm file (and it doesn't allow me to manually change the feed).

This leads me to the question: is there any way at all so that I can add multiple buttons to run macros in this version of office? Preferably something I can build with VBA (command characters are currently being added from VBA).

Since this works in Office for Windows (preview) as well as older versions of office windows, as well as Office 2011 for mac - why not work here?

For reference, here is my test code for creating the command line, extracted 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

      

+3


source to share


2 answers


Create a new .dotm file in Word 2011, run the CreateCommandBar () macro, and then copy the toolbar (using the organizer dialog) and SubItworks () macro into the .dotm file. Place the .dotm file in the Word 2016 startup folder and you will see the toolbar under the Add-ins tab of the ribbon.

It's a buggy - the only controls that seem to work are the top level buttons. Clicking on the popup button does not display the menu, and even the top level buttons do not draw correctly when you click on them.



I was lucky to manually create a new toolbar in Word 2011 (View: Toolbars: Customize Toolbars and Menus ...) and then create buttons by dragging macros onto the toolbar. You can also manually set the properties of the buttons using the Visual Basic Local Objects window as soon as you get a link to the toolbar.

Buttons created this way appear to be correct unless you change any of the button properties at runtime.

+2


source


Office 2016 for Mac now supports customizing the XML Ribbon . Currently experimental / opt -in, but will be enabled by default "early 2016"



0


source







All Articles