Help: how to add custom ribbon to the exe

Example of Creating Ribbon

Step-by-step instruction on how to add your own Tab to the Ribbon

Please, note: Visual Basic code which works with Ribbon should be placed into #If XLC Then ... #End If block.

Why this is important? You can find answer here Using Conditional Statements.

We put this code into Workbook_Open procedure. This event fires always when worbook is opened by application. It is single place where we can do such initialization.

Sub Workbook_Open()
#If XLC Then
 ' Remove all Tabs we have in the default ribbon
 With Application.Ribbon.Tabs
  .Clear
  ' Add new Tab
  With .Add
   ' Set Caption and Tag for this tab
   .Caption = "My Tab"
   .Name = "Tabs.MyTab"
   ' Add button to this tab with Open icon
   With .AddButton
    ' assign caption visible to user
    .Caption = "Open File"
    ' internal name, which we can use in the VB macros
    .Name = "Button.Open.File"
    ' icon
    .Image = "Open.32"
    ' link this button with subroutine
    .OnAction = "OnOpenFile"
   End With
  End With
 End With
#End If
End Sub
' This sub is called when button is pressed
Public Sub OnOpenFile
 MsgBox "OnOpenFile sub is called"
End Sub
		

You need to add your workbook to xlCompiler project and compile it.

After compilation application will have Ribbon with single tab named My Tab, and button Open File.