<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Custom ribbon button doesn't execute VBA sub in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/custom-ribbon-button-doesn-t-execute-vba-sub/m-p/13788549#M176818</link>
    <description>&lt;P&gt;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.&amp;nbsp; The AI suggest that I should alter the security settings, but I cannot find it in Inv 2025 Pro.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Thank you very much in advance.&lt;/P&gt;&lt;LI-CODE lang="visual"&gt;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&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 29 Aug 2025 11:54:02 GMT</pubDate>
    <dc:creator>sv.lucht</dc:creator>
    <dc:date>2025-08-29T11:54:02Z</dc:date>
    <item>
      <title>Custom ribbon button doesn't execute VBA sub</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/custom-ribbon-button-doesn-t-execute-vba-sub/m-p/13788549#M176818</link>
      <description>&lt;P&gt;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.&amp;nbsp; The AI suggest that I should alter the security settings, but I cannot find it in Inv 2025 Pro.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Thank you very much in advance.&lt;/P&gt;&lt;LI-CODE lang="visual"&gt;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&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Aug 2025 11:54:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/custom-ribbon-button-doesn-t-execute-vba-sub/m-p/13788549#M176818</guid>
      <dc:creator>sv.lucht</dc:creator>
      <dc:date>2025-08-29T11:54:02Z</dc:date>
    </item>
    <item>
      <title>Re: Custom ribbon button doesn't execute VBA sub</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/custom-ribbon-button-doesn-t-execute-vba-sub/m-p/13788635#M176819</link>
      <description>&lt;P&gt;This code works and executed the ControlDefinition. It seems that you need a MacroControlDefinition and a called function that resides inside the default.ivb, which sucks because I wanted to keep my code portable in an external ivb.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Public Sub CreateMinimalMacroButton()
' --- 1. Define the names for the macro and UI elements ---
Const MACRO_FULL_NAME As String = "Module1.MyTargetSubroutine"
Const TAB_ID As String = "StampMaker_MinimalTab_1"
Const PANEL_ID As String = "StampMaker_MinimalPanel_1"

Dim uiMgr As UserInterfaceManager
Set uiMgr = ThisApplication.UserInterfaceManager

' --- 2. Clean up any old versions of these UI elements ---
' Using "On Error Resume Next" is a simple way to delete items
' without causing an error if they don't exist yet.
On Error Resume Next

' Delete the Ribbon Tab (this also removes the panel and the button on it)
uiMgr.Ribbons.item("ZeroDoc").RibbonTabs.item(TAB_ID).delete

' Delete the Control Definition (the "brain" of the button)
ThisApplication.CommandManager.ControlDefinitions.item(MACRO_FULL_NAME).delete

' Return to normal error handling
On Error GoTo 0

' --- 3. Create the new UI ---

' Get the ribbon that's visible when no document is open
Dim zeroRibbon As Ribbon
Set zeroRibbon = uiMgr.Ribbons.item("ZeroDoc")

' Create the new tab
Dim myTab As RibbonTab
Set myTab = zeroRibbon.RibbonTabs.Add("Minimal Test", TAB_ID, "ClientID_MinimalTab")

' Create a panel on the tab
Dim myPanel As RibbonPanel
Set myPanel = myTab.RibbonPanels.Add("Test Panel", PANEL_ID, "ClientID_MinimalPanel")

' Create the Macro Definition - this links the button to your code
Dim macroDef As MacroControlDefinition
Set macroDef = ThisApplication.CommandManager.ControlDefinitions.AddMacroControlDefinition(MACRO_FULL_NAME)

' Add the actual button to the panel
Call myPanel.CommandControls.AddMacro(macroDef)

' --- 4. Notify the user ---
MsgBox "Minimal macro button has been created." &amp;amp; vbCrLf &amp;amp; _
"Look for the 'Minimal Test' tab in your ribbon.", vbInformation

End Sub&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 29 Aug 2025 13:02:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/custom-ribbon-button-doesn-t-execute-vba-sub/m-p/13788635#M176819</guid>
      <dc:creator>sv.lucht</dc:creator>
      <dc:date>2025-08-29T13:02:36Z</dc:date>
    </item>
    <item>
      <title>Re: Custom ribbon button doesn't execute VBA sub</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/custom-ribbon-button-doesn-t-execute-vba-sub/m-p/13794048#M176884</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4766162"&gt;@sv.lucht&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is a limitation that the macro should be in the Application project for the ribbon button to call, see documentation below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;A href="https://help.autodesk.com/view/INVNTOR/2025/ENU/?guid=ControlDefinitions_AddMacroControlDefinition" target="_blank"&gt;Inventor 2025 Help | ControlDefinitions.AddMacroControlDefinition Method | Autodesk&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you may find a workaround from below post:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;A href="https://forums.autodesk.com/t5/inventor-programming-ilogic/ribbon-macro-button-to-call-macro-in-second-ivb-project/td-p/9213009" target="_blank"&gt;Solved: Ribbon Macro button to call macro in second ivb project - Autodesk Community&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can call a macro in Application project using your ribbon button, and in your macro it can&amp;nbsp;run another macro in a custom .ivb file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Sep 2025 07:01:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/custom-ribbon-button-doesn-t-execute-vba-sub/m-p/13794048#M176884</guid>
      <dc:creator>YuhanZhang</dc:creator>
      <dc:date>2025-09-03T07:01:01Z</dc:date>
    </item>
  </channel>
</rss>

