创建独特的个性化Office分栏和组--IDBE RibbonCreator 2016 使用入门

是什么?

什么是Ribbon

首先来说下什么是Ribbon。Ribbon是一种以面板及标签页为架构的用户界面(User Interface),原先出现在Microsoft Office 2007后续版本的Word、Excel和PowerPoint等组件中,后来也被运用到Windows 7的一些附加组件等其它软件中,如画图和写字板,以及Windows 8中的资源管理器。ESRI推出的ArcGIS Explorer 9.4也采用这种界面。它是一个收藏了命令按钮和图标的面板。它把命令组织成一组“标签”,每一组包含了相关的命令。每一个应用程序都有一个不同的标签组,展示了程序所提供的功能。在每个标签里,各种的相关的选项被组在一起。设计Ribbon的目的是为了使应用程序的功能更加易于发现和使用,减少了点击鼠标的次数。

Ribbon就是功能区。例如下图中在Excel 2013上功能区(Ribbon)中有个分栏(Tab)“我的工具箱”,在这个分栏中有个组(group)叫做“任务导出工具”,在这个组中有三个按钮控件(Controls)“导出”、“备份”和“恢复”及其上的图标。

IDBE RibbonCreator 2016

IDBE RibbonCreator 2016就是用来自定义生成各Office组件上Ribbon的一款共享软件。支持所见即所得(WYSIWYG,what you see is what you get)。目前支持以下Office组件:

  • Microsoft Access 2013 and 2016
  • Microsoft Excel 2013 and 2016
  • Microsoft PowerPoint 2013 and 2016
  • Microsoft Word 2013 and 2016
  • Office 365 & Office 2016 Click and Run 支持至 1809版本 (Build 10827.20181)

RibbonCreator 2016是一个提供Ribbon开发的所见即所得的界面,它使用VB2005开发,需要.net framework 2.0支持。
它支持以下控件的客户化功能创建:

  • Tabs,
  • Groups,
    • DialogboxLauncher,
  • Labels,
  • Buttons (large or small),
  • ToggleButtons (large or small),
  • Editboxes,
  • Checkboxes,
  • DropDown Controls,
  • ComboBox Controls,
  • ButtonGroups
    • Button and
    • ToggleButton,
  • SplitButtons (large or small),
  • Galleries (large or small) ,
  • Menus (large or small),
  • DynamicMenu (large or small) and
  • Separators (in Menus also with Text)
界面预览

下载链接

百度网盘 提取码: 2k2j
或者这里官方下载

怎么用?

以下以新建一个Excel 2013上Ribbon为例,来介绍下入门用法。

打开IDBE RibbonCreator 2016

新建或打开

点击Home新建一个文件,或者点击File选择已有文件, 选择左侧已存在文件..an Excel Workbook, 选择右侧最近使用的excel文档

如果该文件以前没有自定义Ribbon,则出现以下提示

以下以新建一个为例,点击Home,右侧Target Application选择Excel图标点击(默认为第一个,Access)

创建分栏Tabs

点击“Add Tab”可以创建一个新分栏,TAB 1(默认即一个分栏,名为HOME);点击“Delete Selected Tab”删除当前分栏

输入分栏名称,例如:我的工具箱,点击rename可以修改分栏名称

共享软件最多支持2个分栏(Tabs)

创建组Groups

点击“Group”, 进入组设置。在组设置中,点击“Add Group”, 点击“Delete Selected Group”删除当前选定组

通过“Label”下文本框输入组名称, 点击“Rename”修改

共享软件最多支持3个组(Groups)

创建控件Controls

点击“Controls”分栏进入控件设置。如果有多个组,则选择左侧前一步设置组名称。
点击右侧“Add:”下各控件,将控件添加入当前组。此处以添加三个按钮控件为例。

点击“Delete Button”可以删除此按钮控件。通过"Rename"设置控件名称,“ScreenTip”设置鼠标停留提示等。

点击“Edit Callbacks/Tags”,设置onAction为“onActionButtonExport”。

点击“Edit Control ID”修改控件ID,此处修改控件ID为btnExport,btn为按钮控件的前缀。

点击“Select Image”选择控件图标。其他两个按钮也按照以上步骤完成。

共享软件最多支持10个控件(Controls)

共享软件最多支持2个分栏(Tabs),最多支持3个组(Groups),最多支持10个控件(Controls)。可以购买获取个性化授权文件解锁这些限制,购买链接

结束

点击“Finish”分栏,进入最后设置。

勾选“Show Standard Ribbons”选项,保存或另存为带有宏的Excel工作簿,xlsm格式。

以上设置也可以查看自动生成的配置文件(xml格式),可以点击“Get RibbonXML (TEXT File)”按钮。有些工具可以按照此格式手工创建xml,然后生成xlsm文件。

点击查看配置文件代码
<!-- Created with IDBE RibbonCreator 2016 (Version: 1.1006e) -->
<!--                 http://www.RibbonCreator2016.de                -->

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="OnRibbonLoad" loadImage="LoadImages">
  <ribbon startFromScratch="false">
    <tabs>
      <tab id="tab0" label="我的工具箱" getVisible ="GetVisible">
        <group id="grp0" autoScale="false" centerVertically="false" label="任务导出组" getVisible ="GetVisible" tag = "RibbonName:=;inMenu:=;CustomTagValue1:=;CustomTagValue2:=;CustomTagValue3:=;CustomPicture:=;CustomPicturePath:=" imageMso="AccessFormDatasheet" >
          <button id="btnExport" size="large" label="导出" screentip="导出任务" supertip="导出任务SuperTip" imageMso="ExportExcel" tag="RibbonName:=;inMenu:=;CustomTagValue1:=;CustomTagValue2:=;CustomTagValue3:=;CustomPicture:=;CustomPicturePath:=" onAction="OnActionButtonExport" getVisible="GetVisible" getEnabled="GetEnabled" />
          <button id="btnBackup" size="large" label="备份" screentip="备份统计数据" supertip="备份统计数据supertip" imageMso="BackupSite" tag="RibbonName:=;inMenu:=;CustomTagValue1:=;CustomTagValue2:=;CustomTagValue3:=;CustomPicture:=;CustomPicturePath:=" onAction="OnActionButtonBackup" getVisible="GetVisible" getEnabled="GetEnabled" />
          <button id="btnRestore" size="large" label="恢复" screentip="恢复统计数据" supertip="恢复统计数据supertip" imageMso="RestoreSite" tag="RibbonName:=;inMenu:=;CustomTagValue1:=;CustomTagValue2:=;CustomTagValue3:=;CustomPicture:=;CustomPicturePath:=" onAction="OnActionButtonRestore" getVisible="GetVisible" getEnabled="GetEnabled" />
        </group>
      </tab>
    </tabs>
  </ribbon>
</customUI>

点击“Get Callbacks(TEXT File)”按钮,查看自动生成的回调函数(也可以随后打开VBA编辑器查看),特别关注下OnActionButton(control As IRibbonControl)过程

点击查看模块代码
'################################################################
'#                                                              #
'#      Created with / Erstellt mit:                            #
'#      IDBE RibbonCreator 2016                                 #
'#      Version: 1.1006e                                        #
'#                                                              #
'#      (c) 2007-2022 IDBE Avenius                              #
'#                                                              #
'#      http://www.ribboncreator2016.de/en                      #
'#      http://www.ribboncreator2010.com                        #
'#      http://www.ribboncreator.com                            #
'#      http://www.accessribon.com                              #
'#      http://www.avenius.com                                  #
'#                                                              #
'#      You may send change requests or report errors to:       #
'#      Aenderungswuensche oder Fehler bitte an:                #
'#                                                              #
'#      mailto://info@ribboncreator2016.de                      #
'#                                                              #
'################################################################


' Globals:


Public gobjRibbon As IRibbonUI

Public bolEnabled As Boolean    ' Used in Callback "getEnabled"
                                ' Further informations in Callback "getEnabled"
                                ' Für Callback "getEnabled"
                                ' Genauere Informationen in Callback "getEnabled".
                               
Public bolVisible As Boolean    ' Used in Callback "getVisible"
                                ' More information in Callback "getVisible
                                ' Für Callback "getVisible"
                                ' Further informations in Callback "getVisible

' For Sample Callback "GetContent"
' Fuer Beispiel Callback "GetContent"
Public Type ItemsVal
    id As String
    label As String
    imageMso As String
End Type


' Callbacks

Public Sub OnRibbonLoad(ribbon As IRibbonUI)
'Callbackname in XML File "onLoad"

    Set gobjRibbon = ribbon
End Sub

Public Sub OnActionButton(control As IRibbonControl)
'Callback in XML File "onAction"

    ' Callback for event button click
    ' Callback für Button Click
    
    Select Case control.id
        
        Case "btnExport"
            ' In Tab:   tab0
            ' In Group: grp0
            MsgBox "Button """ &  control.ID & """ clicked" & vbCrLf & _
                   "Es wurde auf Button """ &  control.ID & """ im Ribbon geklickt", _
                   vbInformation
        Case "btnBackup"
            ' In Tab:   tab0
            ' In Group: grp0
            MsgBox "Button """ &  control.ID & """ clicked" & vbCrLf & _
                   "Es wurde auf Button """ &  control.ID & """ im Ribbon geklickt", _
                   vbInformation
        Case "btnRestore"
            ' In Tab:   tab0
            ' In Group: grp0
            MsgBox "Button """ &  control.ID & """ clicked" & vbCrLf & _
                   "Es wurde auf Button """ &  control.ID & """ im Ribbon geklickt", _
                   vbInformation

        Case Else
            MsgBox "Button """ & control.id & """ clicked" & vbCrLf & _
                           "Es wurde auf Button """ & control.id & """ in Ribbon geklickt", _
                           vbInformation
    End Select
End Sub

'Command Button

Sub OnActionButtonHelp(control As IRibbonControl, ByRef CancelDefault)
    ' Callbackname in XML File Command "onAction"

    ' Callback for command event button click
    ' Callback fuer Command Button Click

    MsgBox "Button ""Help"" clicked" & vbCrLf & _
                           "Es wurde auf Button ""Hilfe"" geklickt", _
                           vbInformation
    CancelDefault = True

End Sub

Sub OnActionCheckBox(control As IRibbonControl, _
                               pressed As Boolean)
    ' Callbackname in XML File "OnActionCheckBox"
    
    ' Callback for event checkbox click
    ' Callback für Checkbox Click

    Select Case control.id
        

        Case Else
            MsgBox "The Value of the Checkbox """ & control.id & """ is: " & pressed & vbCrLf & _
                   "Der Wert der Checkbox """ & control.id & """ ist: " & pressed, _
                   vbInformation
    End Select

End Sub

Sub GetPressedCheckBox(control As IRibbonControl, _
                       ByRef bolReturn)
    
    ' Callbackname in XML File "GetPressedCheckBox"
    
    ' Callback for checkbox
    ' indicates how the control is displayed
    ' Callback für Checkbox wie das Control
    ' angezeigt werden soll

    Select Case control.id
        

        Case Else
            If getTheValue(control.Tag, "DefaultValue") = "1" Then
                bolReturn = True
            Else
                bolReturn = False
            End If
    End Select

End Sub


Sub OnActionTglButton(control As IRibbonControl, _
                       pressed As Boolean)
                              
    ' Callbackname in XML File "onAction"
    
    ' Callback für einen Toggle Button Klick
    ' Callback for a Toggle Buttons click event

    Select Case control.id
        

        Case Else
            MsgBox "The Value of the Toggle Button """ & control.id & """ is: " & pressed & vbCrLf & _
                   "Der Wert der Toggle Button """ & control.id & """ ist: " & pressed, _
                   vbInformation
    End Select

End Sub

Sub GetPressedTglButton(control As IRibbonControl, _
                       ByRef pressed)
' Callbackname in XML File "getPressed"

' Callback für ein Access ToogleButton Control wie dieser Angezeigt werden soll
' Callback for an Access ToogleButton Control. Indicates how the control is displayed

    Select Case control.id
        

        Case Else
            If getTheValue(control.Tag, "DefaultValue") = "1" Then
                pressed = True
            Else
                pressed = False
            End If
    End Select
End Sub

Public Sub GetEnabled(control As IRibbonControl, ByRef enabled)
    ' Callbackname in XML File "getEnabled"
    
    ' To set the property "enabled" to a Ribbon Control
    ' For further information see: http://www.accessribbon.de/en/index.php?Downloads:12
    ' Setzen der Enabled Eigenschaft eines Ribbon Controls
    ' Weitere Informationen: http://www.accessribbon.de/index.php?Downloads:12

    Select Case control.id
        
        Case "btnExport"
            ' Button
            ' In Tab:   tab0
            ' In Group: grp0
            Enabled = True
        Case "btnBackup"
            ' Button
            ' In Tab:   tab0
            ' In Group: grp0
            Enabled = True
        Case "btnRestore"
            ' Button
            ' In Tab:   tab0
            ' In Group: grp0
            Enabled = True

        Case Else
            enabled = True
    End Select
End Sub

Public Sub GetVisible(control As IRibbonControl, ByRef visible)
    ' Callbackname in XML File "getVisible"
    
    ' To set the property "visible" to a Ribbon Control
    ' For further information see: http://www.accessribbon.de/en/index.php?Downloads:12
    ' Setzen der Visible Eigenschaft eines Ribbon Controls
    ' Weitere Informationen: http://www.accessribbon.de/index.php?Downloads:12

    Select Case control.id
        
        Case "btnExport"
            ' Button
            ' In Tab:   tab0
            ' In Group: grp0
            Visible = True
        Case "btnBackup"
            ' Button
            ' In Tab:   tab0
            ' In Group: grp0
            Visible = True
        Case "btnRestore"
            ' Button
            ' In Tab:   tab0
            ' In Group: grp0
            Visible = True
        Case "grp0"
            ' Group:    grp0
            ' In Tab:   tab0
            Visible = True
        Case "tab0"
            ' Tab:   tab0
            Visible = True

        Case Else
            visible = True
    End Select
End Sub

Sub GetLabel(control As IRibbonControl, ByRef label)
    ' Callbackname in XML File "getLabel"
    ' To set the property "label" to a Ribbon Control

    Select Case control.ID
        

        Case Else
            label = "*getLabel*"

    End Select

End Sub

Sub GetScreentip(control As IRibbonControl, ByRef screentip)
    ' Callbackname in XML File "getScreentip"
    ' To set the property "screentip" to a Ribbon Control

    Select Case control.ID
        

        Case Else
            screentip = "*getScreentip*"

    End Select

End Sub

Sub GetSupertip(control As IRibbonControl, ByRef supertip)
    ' Callbackname in XML File "getSupertip"
    ' To set the property "supertip" to a Ribbon Control

    Select Case control.ID
        

        Case Else
            supertip = "*getSupertip*"

    End Select

End Sub

Sub GetDescription(control As IRibbonControl, ByRef description)
    ' Callbackname in XML File "getDescription"
    ' To set the property "description" to a Ribbon Control

    Select Case control.ID
        

        Case Else
            description = "*getDescription*"

    End Select

End Sub

Sub GetTitle(control As IRibbonControl, ByRef title)
    ' Callbackname in XML File "getTitle"
    ' To set the property "title" to a Ribbon MenuSeparator Control

    Select Case control.ID
        

        Case Else
            title = "*getTitle*"

    End Select

End Sub


'EditBox

Sub GetTextEditBox(control As IRibbonControl, _
                             ByRef strText)
    ' Callbackname in XML File "GetTextEditBox"
    
    ' Callback für EditBox welcher Wert in der
    ' EditBox eingetragen werden soll.
    ' Callback for an EditBox Control
    ' Indicates which value is to set to the control

    Select Case control.id
        

        Case Else
            strText = getTheValue(control.Tag, "DefaultValue")
    End Select
    
End Sub

Sub OnChangeEditBox(control As IRibbonControl, _
                              strText As String)
    ' Callbackname in XML File "OnChangeEditBox"
    
    ' Callback Editbox: Rückgabewert der Editbox
    ' Callback Editbox: Return value of the Editbox

    Select Case control.id
        

        Case Else
            MsgBox "The Value of the EditBox """ & control.id & """ is: " & strText & vbCrLf & _
                   "Der Wert der EditBox """ & control.id & """ ist: " & strText, _
                   vbInformation
    End Select

End Sub

'DropDown

Sub OnActionDropDown(control As IRibbonControl, _
                             selectedId As String, _
                             selectedIndex As Integer)
    ' Callbackname in XML File "OnActionDropDown"
    
    ' Callback onAction (DropDown)
    
    Select Case control.id
        

        Case Else
            MsgBox "The selected ItemID of DropDown-Control """ & control.id & """ is : """ & selectedId & """" & vbCrLf & _
                   "Die selektierte ItemID des DropDown-Control """ & control.id & """ ist : """ & selectedId & """", _
                   vbInformation
    End Select

End Sub

Sub GetSelectedItemIndexDropDown(control As IRibbonControl, _
                                 ByRef index)
    ' Callbackname in XML File "GetSelectedItemIndexDropDown"
    
    ' Callback getSelectedItemIndex (DropDown)
    
    Dim varIndex As Variant
    varIndex = getTheValue(control.Tag, "DefaultValue")
    
    If IsNumeric(varIndex) Then
        Select Case control.id
            

            Case Else
                index = varIndex
        End Select
    End If

End Sub

'Gallery

Sub OnActionGallery(control As IRibbonControl, _
                     selectedId As String, _
                     selectedIndex As Integer)
    ' Callbackname in XML File "OnActionGallery"
    
    ' Callback onAction (Gallery)
    
    Select Case control.id
        

        Case Else
            Select Case selectedId
                Case Else
                    MsgBox "The selected ItemID of Gallery-Control """ & control.id & """ is : """ & selectedId & """" & vbCrLf & _
                           "Die selektierte ItemID des Gallery-Control """ & control.id & """ ist : """ & selectedId & """", _
                           vbInformation
            End Select
    End Select

End Sub

Sub GetSelectedItemIndexGallery(control As IRibbonControl, _
                                   ByRef index)
    ' Callbackname in XML File "GetSelectedItemIndexGallery"
    
    ' Callback getSelectedItemIndex (Gallery)
    
    Dim varIndex As Variant
    varIndex = getTheValue(control.Tag, "DefaultValue")
    
    If IsNumeric(varIndex) Then
        Select Case control.id
            

            Case Else
                index = varIndex

        End Select

    End If

End Sub

'Combobox

Sub GetTextComboBox(control As IRibbonControl, _
                      ByRef strText)

    ' Callbackname im XML File "GetTextComboBox"
    
    ' Callback getText (Combobox)
                           
    Select Case control.id
        

        Case Else
            strText = getTheValue(control.Tag, "DefaultValue")
    End Select

End Sub


Sub OnChangeComboBox(control As IRibbonControl, _
                               strText As String)
                           
    ' Callbackname im XML File "OnChangeCombobox"
    
    ' Callback onChange (Combobox)
   
    Select Case control.id
        

        Case Else
            MsgBox "The selected Item of Combobox-Control """ & control.id & """ is : """ & strText & """" & vbCrLf & _
                   "Das selektierte Item des Combobox-Control """ & control.id & """ ist : """ & strText & """", _
                   vbInformation
    End Select

End Sub


' DynamicMenu

Sub GetContent(control As IRibbonControl, _
               ByRef XMLString)

    ' Sample for a Ribbon XML "getContent" Callback
    ' See also http://www.accessribbon.de/en/index.php?Access_-_Ribbons:Callbacks:dynamicMenu_-_getContent
    '     and: http://www.accessribbon.de/en/index.php?Access_-_Ribbons:Ribbon_XML___Controls:Dynamic_Menu

    ' Beispiel fuer einen Ribbon XML - "getContent" Callback
    ' Siehe auch: http://www.accessribbon.de/index.php?Access_-_Ribbons:Callbacks:dynamicMenu_-_getContent
    '       und : http://www.accessribbon.de/?Access_-_Ribbons:Ribbon_XML___Controls:Dynamic_Menu

    Select Case control.id
        

        Case Else
            XMLString = getXMLForDynamicMenu()
    End Select
 
End Sub


' Helper Function
' Hilfsfunktionen

Public Function getXMLForDynamicMenu() As String
    
    ' Creates a XML String for DynamicMenu CallBack - getContent
    
    ' Erstellt den Inhalt fuer das DynamicMenu im Callback getContent
    
    Dim lngDummy    As Long
    Dim strDummy    As String
    Dim strContent  As String
    
    Dim Items(4) As ItemsVal
    Items(0).id = "btnDy1"
    Items(0).label = "Item 1"
    Items(0).imageMso = "_1"
    Items(1).id = "btnDy2"
    Items(1).label = "Item 2"
    Items(1).imageMso = "_2"
    Items(2).id = "btnDy3"
    Items(2).label = "Item 3"
    Items(2).imageMso = "_3"
    Items(3).id = "btnDy4"
    Items(3).label = "Item 4"
    Items(3).imageMso = "_4"
    Items(4).id = "btnDy5"
    Items(4).label = "Item 5"
    Items(4).imageMso = "_5"
    
    strDummy = "<menu xmlns=""http://schemas.microsoft.com/office/2009/07/customui"">" & vbCrLf
    
        For lngDummy = LBound(Items) To UBound(Items)
            strContent = strContent & _
                "<button id=""" & Items(lngDummy).id & """" & _
                " label=""" & Items(lngDummy).label & """" & _
                " imageMso=""" & Items(lngDummy).imageMso & """" & _
                " onAction=""OnActionButton""/>" & vbCrLf
        Next
 

    strDummy = strDummy & strContent & "</menu>"
    getXMLForDynamicMenu = strDummy

End Function

Public Function getTheValue(strTag As String, strValue As String) As String
   ' *************************************************************
   ' Erstellt von     : Avenius
   ' Parameter        : Input String, SuchValue String
   ' Erstellungsdatum : 05.01.2008
   ' Bemerkungen      :
   ' Änderungen       :
   '
   ' Beispiel
   ' getTheValue("DefaultValue:=Test;Enabled:=0;Visible:=1", "DefaultValue")
   ' Return           : "Test"
   ' *************************************************************
      
   On Error Resume Next
      
   Dim workTb()     As String
   Dim Ele()        As String
   Dim myVariabs()  As String
   Dim i            As Integer

      workTb = Split(strTag, ";")
      
      ReDim myVariabs(LBound(workTb) To UBound(workTb), 0 To 1)
      For i = LBound(workTb) To UBound(workTb)
         Ele = Split(workTb(i), ":=")
         myVariabs(i, 0) = Ele(0)
         If UBound(Ele) = 1 Then
            myVariabs(i, 1) = Ele(1)
         End If
      Next
      
      For i = LBound(myVariabs) To UBound(myVariabs)
         If strValue = myVariabs(i, 0) Then
            getTheValue = myVariabs(i, 1)
         End If
      Next
      
End Function

点击“Open Workbook in Excel”按钮可以立即打开此工作簿查看。

在打开的工作簿中,点击“我的工具箱“菜单栏,点击“导出”按钮,提示OnActionButtonExport宏未定义,因为对于按钮控件只有一个OnActionButton的回调入口。

点击Excel中“开发工具”菜单下查看代码,打开VBA编辑器。在VBA编辑器中,打开左侧模块,可以看到自动生成的模块baseCallbacks,这里面的代码即以上回调代码。

注意到这里只有OnActionButton函数,按照该函数格式自定义OnActionButtonExport,OnActionButtonBackup,OnActionButtonRestore等,即此前RibbonCreator 2016中定义的各控件的回调名称。

再次回到Excel文件中,点击“导出”按钮,可以看到宏定义完成了。接下去就可以使用VBA完成更多业务功能了!

最后

RibbonCreator 2016此处只做简要使用入门介绍,还有其他高级功能待摸索。

posted @ 2022-01-06 15:22  devdog  阅读(989)  评论(0编辑  收藏  举报