Message 1 of 4
VBA - Add a custom macro on a custom panel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I'm trying to add a macro on a custom panel.
I create the tab, the panel, the macro button... but I can't make the button launch the macro !
Here's the code, what's wrong ?
Public Sub test()
MsgBox ("Hello")
End Sub
Private Sub create_macro_button()
Dim oAssemblyRibbon As Ribbon
Dim oCustomTab As RibbonTab
Dim oCustomPanel As RibbonPanel
Set oAssemblyRibbon = ThisApplication.UserInterfaceManager.Ribbons.item("Assembly")
'Create tab "Custom"
On Error Resume Next
Call oAssemblyRibbon.RibbonTabs("TabCustomIntName").Delete
On Error GoTo 0
Call oAssemblyRibbon.RibbonTabs.Add("Custom", "TabCustomIntName", "CustomId")
Set oCustomTab = oAssemblyRibbon.RibbonTabs("TabCustomIntName")
'Create panel "Custom"
On Error Resume Next
Call oCustomTab.RibbonPanels.item("PanelCustomIntName").Delete
On Error GoTo 0
Call oCustomTab.RibbonPanels.Add("Custom", "PanelCustomIntName", "CustomId")
Set oCustomPanel = oCustomTab.RibbonPanels.item("PanelCustomIntName")
'****************************************************************
'Macro definition
macroInternalName = "Macro"
On Error Resume Next
Call ThisApplication.CommandManager.ControlDefinitions.item(macroInternalName).Delete
On Error GoTo 0
Dim oMacroDef As MacroControlDefinition
Set oMacroDef = ThisApplication.CommandManager.ControlDefinitions.AddMacroControlDefinition("Module1.test")
Call oCustomPanel.CommandControls.AddMacro(oMacroDef, False)
End Sub