mac 的 Word 2016 - 任何类型的自定义控件

Word 2016 for mac - Any kind of custom controls

我有一个 Word 插件。在 windows 的 office 上,它可以使用功能区 XML 显示自定义功能区。在 mac 的 office 2011 上,它会忽略此功能区,但我可以添加一个 CommandBar(顶部的下拉菜单)。这些允许我为我的各种 macros 创建一个菜单系统。

在 Office 2016 中,当我尝试创建命令栏时出现错误:"Method 'Add' of Object 'CommandBarControls' failed。它也不允许自定义色带,它不会选择 dotm 文件中的 XML(它似乎也不允许我手动更改色带)。

这让我想到了一个问题 - 有没有什么办法,我可以在某处添加一些按钮来在这个版本的 office 上触发 macros?最好是我可以使用 VBA 创建的东西(目前命令栏是从 VBA 添加的)。

因为这适用于 Windows(预览版)的 Office 以及适用于 windows 的旧版 office,以及适用于 mac 的 Office 2011 - 为什么这不行在这里工作?

作为参考,这是我创建命令栏的测试代码,来自 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

在 Word 2011 中创建一个新的 .dotm 文件,运行 CreateCommandBar() 宏,然后将工具栏(使用管理器对话框)和 SubItworks() 宏复制到 .dotm 文件。将 .dotm 文件放入 Word 2016 的启动文件夹中,您将在功能区的加载项选项卡中看到工具栏。

尽管它有问题 - 唯一似乎有效的控件是顶级按钮。单击弹出按钮不会显示菜单,甚至在您单击顶级按钮时也无法正确绘制它们。

我在 Word 2011 中手动创建了一个新的工具栏(视图:工具栏:自定义工具栏和菜单...),然后通过将宏拖动到工具栏来创建按钮。一旦获得对工具栏的引用,您还可以使用 Visual Basic 的局部变量 window 手动设置按钮属性。

只要您在 运行 时不更改任何按钮属性,以这种方式创建的按钮似乎会正常运行。

Macnow supports Ribbon XML customization 的 Office 2016。当前 experimental/opt-in,但将默认启用 "in early 2016"