Custom ribbon button doesn't execute VBA sub
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I try to create custom ribbon tabs that get called when different criteria are met. The VBA code resides in StampMaker.ivb library in the UIManager module and everything works fine. I can create and destroy tabs,panel,buttons, but I cannot make the buttons work. The functions get never called. I tried to simplify the code, as seen below. I tried to get help from Gemini. But nothing works. So I would be very grateful for any suggestions. Here is a simplified version of the code just for troubleshooting. I checked all the names. I counted the ControlDefinitions and the count increases when the object is created, so the object exists. I can delete and recreate it just fine. But I cannot make the link to the Sub working. I tried to call a function in the default library, but this doesn't work either. I tried MacroButtons, but the same problem. The AI suggest that I should alter the security settings, but I cannot find it in Inv 2025 Pro.
Thank you very much in advance.
Public Sub RunCleanButtonTest()
' --- Phase 1: Aggressive Cleanup ---
'Const TEST_MACRO_NAME As String = "Default.Module1.testio"
Const TEST_MACRO_NAME As String = "StampMaker.UIManager.testprompt"
Const TEST_TAB_NAME As String = "MyTestTab"
Const TEST_PANEL_NAME As String = "MyTestPanel"
' Delete the Control Definition
On Error Resume Next
ThisApplication.CommandManager.ControlDefinitions.item(TEST_MACRO_NAME).delete
Debug.Print "Old Control Definition deleted (if it existed)."
On Error GoTo 0
' Delete the Ribbon Tab
Dim zeroRibbon As Inventor.Ribbon
Set zeroRibbon = ThisApplication.UserInterfaceManager.Ribbons.item("ZeroDoc")
On Error Resume Next
zeroRibbon.RibbonTabs.item(TEST_TAB_NAME).delete
Debug.Print "Old Ribbon Tab deleted (if it existed)."
On Error GoTo 0
' --- Phase 2: Create a single, simple button ---
Debug.Print "Creating new UI..."
' Create Tab and Panel
Dim newTab As RibbonTab
Set newTab = zeroRibbon.RibbonTabs.Add("My Test", TEST_TAB_NAME, "ClientID_TestTab")
Dim newPanel As RibbonPanel
Set newPanel = newTab.RibbonPanels.Add("My Panel", TEST_PANEL_NAME, "ClientID_TestPanel")
' Create Button Definition
Dim buttonDef As ButtonDefinition
Set buttonDef = ThisApplication.CommandManager.ControlDefinitions.AddButtonDefinition( _
"Click Me", _
TEST_MACRO_NAME, _
CommandTypesEnum.kNonShapeEditCmdType)
' Add button to panel
Call newPanel.CommandControls.AddButton(buttonDef, True)
Debug.Print "--- Test UI created. Please click the 'Click Me' button on the 'My Test' tab. ---"
End Sub
Public Sub testprompt()
Debug.Print ("HEUREKA! it works")
Debug.Print ("HEUREKA! it works")
Debug.Print ("HEUREKA! it works")
End Sub