<?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 Re: Ribbon Macro button to call macro in second ivb project in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/ribbon-macro-button-to-call-macro-in-second-ivb-project/m-p/9228835#M68472</link>
    <description>&lt;P&gt;Please notice that this is not supported to call the macro in a user/document VBA project using macro control definition, see the Description for&amp;nbsp;&lt;SPAN&gt;MacroOrProgram argument in the&amp;nbsp;&lt;STRONG&gt;AddMacroControlDefinition method:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://help.autodesk.com/view/INVNTOR/2020/ENU/?guid=GUID-B769BA2B-85D0-4026-A677-FDC660306389" target="_blank"&gt;http://help.autodesk.com/view/INVNTOR/2020/ENU/?guid=GUID-B769BA2B-85D0-4026-A677-FDC660306389&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you can try to call another macro in different project in your macro, below is a sample:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; 1. Download the MyProj.ivb to C:\Temp folder, it has a simple macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; 2. Copy below VBA code to your ApplicationProject.&lt;/P&gt;
&lt;PRE&gt;Sub CallMacroFromAnotherProj()
    ' you should specify the IVB path and name firstly.
    Dim sIVBPath As String
    sIVBPath = "C:\temp\MyProj.ivb"
    
    Dim sIVBName As String
    sIVBName = "TestNew"
    
    Call ThisApplication.VBAProjects.Open(sIVBPath)
    
    Dim oVBAProj As InventorVBAProject
    Dim oTempProj As InventorVBAProject
    
    For Each oTempProj In ThisApplication.VBAProjects
        If oTempProj.ProjectType = kUserVBAProject Then
            If oTempProj.Name = sIVBName Then
                Set oVBAProj = oTempProj
                Exit For
            End If
        End If
    Next
    
    Debug.Print oVBAProj.Name
    
    Dim oVBAComp As InventorVBAComponent
    Set oVBAComp = oVBAProj.InventorVBAComponents.Item("Module1")
    
    Debug.Print oVBAComp.Name
    
    Dim oVBAMember As InventorVBAMember
    Set oVBAMember = oVBAComp.InventorVBAMembers.Item("test")
    
    Debug.Print oVBAMember.Name
    oVBAMember.Execute
    
End Sub&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; 3. Add the macro to ribbon, and try it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope above helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 03 Jan 2020 07:28:14 GMT</pubDate>
    <dc:creator>YuhanZhang</dc:creator>
    <dc:date>2020-01-03T07:28:14Z</dc:date>
    <item>
      <title>Ribbon Macro button to call macro in second ivb project</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ribbon-macro-button-to-call-macro-in-second-ivb-project/m-p/9213009#M68471</link>
      <description>&lt;P&gt;I am trying to a a button to the ribbon that will call a macro that is not located in the default.ivb file. Is there anyway to link a button to a procedure located in a second project?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The below code add the tab and button to the ribbon while in the drawing environment. If there is a procedure call MyMessage located in the Default.ivb project, everything works. If I move the procedure to the second project I cannot seem to get it to be called.&lt;/P&gt;&lt;P&gt;using something like "VbaProject2.addbuttontoribbon.MyMessage" doesn't seem to work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas would be welcomed. Thanks!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The tree starts out like this:&lt;/P&gt;&lt;P&gt;ApplicationProject (Default.ivb)&lt;/P&gt;&lt;P&gt;VbaProject 2 (VbaProject2.ivb)&lt;/P&gt;&lt;P&gt;-addbuttontoribbon&lt;/P&gt;&lt;P&gt;&amp;nbsp; Sub MyMessage()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Sub AddButton2()
        Dim oDoc As DrawingDocument
        Set oDoc = ThisApplication.ActiveDocument

        Dim oRibbon As Ribbon: Set oRibbon = ThisApplication.UserInterfaceManager.Ribbons.item("Drawing")

        Dim oRibbonTabs As RibbonTabs: Set oRibbonTabs = oRibbon.RibbonTabs
        Dim oRibbonTab As RibbonTab
        For Each oRibbonTab In oRibbonTabs
            If oRibbonTab.InternalName = "Id_TabTab" Then
            Exit For
            End If
        Next
        If oRibbonTab Is Nothing Then Set oRibbonTab = oRibbon.RibbonTabs.Add("Tab", "Id_TabTab", "", "", True, False) 'only works on initial run
           
        Dim oRibbonPanels As RibbonPanels: Set oRibbonPanels = oRibbonTab.RibbonPanels
        Dim oRibbonPanel As RibbonPanel
        For Each oRibbonPanel In oRibbonPanels
            If oRibbonPanel.InternalName = "Drawing.id_TabTab.Tab" Then
            Exit For
            End If
        Next
        If oRibbonPanel Is Nothing Then Set oRibbonPanel = oRibbonTab.RibbonPanels.Add("Tab", "Drawing.id_TabTab.Tab", "") 'only works on initial run
        
        
    Dim oCommandControl As CommandControl
    Dim oCommandControls As CommandControls: Set oCommandControls = oRibbonPanel.CommandControls
    
'add a macrobutton with non macro icon

    Set oCommandControl = Nothing
     For Each oCommandControl In oCommandControls
        If oCommandControl.InternalName = "macro:AddButtonToRibbon.MyMessage" Then
        oCommandControl.Delete
        Set oCommandControl = Nothing
        Exit For
        End If
     Next
     
     
    Dim oMacroControlDef As MacroControlDefinition
    Set oMacroControlDef = ThisApplication.CommandManager.ControlDefinitions.AddMacroControlDefinition("AddButtonToRibbon.MyMessage")
        
       If oCommandControl Is Nothing Then Set oCommandControl = oRibbonPanel.CommandControls.AddMacro(oMacroControlDef, False, True, "", False)
       
        oRibbonTab.Visible = True
        oRibbonPanel.Visible = True

End Sub&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Dec 2019 21:37:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ribbon-macro-button-to-call-macro-in-second-ivb-project/m-p/9213009#M68471</guid>
      <dc:creator>cshunt</dc:creator>
      <dc:date>2019-12-19T21:37:15Z</dc:date>
    </item>
    <item>
      <title>Re: Ribbon Macro button to call macro in second ivb project</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ribbon-macro-button-to-call-macro-in-second-ivb-project/m-p/9228835#M68472</link>
      <description>&lt;P&gt;Please notice that this is not supported to call the macro in a user/document VBA project using macro control definition, see the Description for&amp;nbsp;&lt;SPAN&gt;MacroOrProgram argument in the&amp;nbsp;&lt;STRONG&gt;AddMacroControlDefinition method:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://help.autodesk.com/view/INVNTOR/2020/ENU/?guid=GUID-B769BA2B-85D0-4026-A677-FDC660306389" target="_blank"&gt;http://help.autodesk.com/view/INVNTOR/2020/ENU/?guid=GUID-B769BA2B-85D0-4026-A677-FDC660306389&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you can try to call another macro in different project in your macro, below is a sample:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; 1. Download the MyProj.ivb to C:\Temp folder, it has a simple macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; 2. Copy below VBA code to your ApplicationProject.&lt;/P&gt;
&lt;PRE&gt;Sub CallMacroFromAnotherProj()
    ' you should specify the IVB path and name firstly.
    Dim sIVBPath As String
    sIVBPath = "C:\temp\MyProj.ivb"
    
    Dim sIVBName As String
    sIVBName = "TestNew"
    
    Call ThisApplication.VBAProjects.Open(sIVBPath)
    
    Dim oVBAProj As InventorVBAProject
    Dim oTempProj As InventorVBAProject
    
    For Each oTempProj In ThisApplication.VBAProjects
        If oTempProj.ProjectType = kUserVBAProject Then
            If oTempProj.Name = sIVBName Then
                Set oVBAProj = oTempProj
                Exit For
            End If
        End If
    Next
    
    Debug.Print oVBAProj.Name
    
    Dim oVBAComp As InventorVBAComponent
    Set oVBAComp = oVBAProj.InventorVBAComponents.Item("Module1")
    
    Debug.Print oVBAComp.Name
    
    Dim oVBAMember As InventorVBAMember
    Set oVBAMember = oVBAComp.InventorVBAMembers.Item("test")
    
    Debug.Print oVBAMember.Name
    oVBAMember.Execute
    
End Sub&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; 3. Add the macro to ribbon, and try it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope above helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jan 2020 07:28:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ribbon-macro-button-to-call-macro-in-second-ivb-project/m-p/9228835#M68472</guid>
      <dc:creator>YuhanZhang</dc:creator>
      <dc:date>2020-01-03T07:28:14Z</dc:date>
    </item>
    <item>
      <title>Re: Ribbon Macro button to call macro in second ivb project</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ribbon-macro-button-to-call-macro-in-second-ivb-project/m-p/9228837#M68473</link>
      <description>&lt;P&gt;Seems the attachment is missing, reattach it.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jan 2020 07:31:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ribbon-macro-button-to-call-macro-in-second-ivb-project/m-p/9228837#M68473</guid>
      <dc:creator>YuhanZhang</dc:creator>
      <dc:date>2020-01-03T07:31:03Z</dc:date>
    </item>
    <item>
      <title>Re: Ribbon Macro button to call macro in second ivb project</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ribbon-macro-button-to-call-macro-in-second-ivb-project/m-p/9229363#M68474</link>
      <description>&lt;P&gt;Thanks for the reply. I have a function very similar the one you posted, it pulls up a user form for controls.&lt;/P&gt;&lt;P&gt;I now realize that a button for a macro cannot be placed on the ribbon because on startup, that macro is not available until the external ivb project is loaded.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It would be nice if inventor would allow multiple .ivb projects to be loaded on the options screen. i.e. separatoed by a ";" or comma.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Dim oApp As Application: Set oApp = ThisApplication
Dim oProjectName As String: oProjectName = "InventorMacros"
Dim oModuleName As String: oModuleName = "Module1"
Dim oMacroName As String: oMacroName = "ShowExternalForm"

Dim ProjectLocation As String: ProjectLocation = "c:\temp\InventorMacros.ivb"

Dim oProjects As InventorVBAProjects: Set oProjects = ThisApplication.VBAProjects

Dim oProject As InventorVBAProject

Dim ProjectFound As Boolean: ProjectFound = False
Set oProjects = ThisApplication.VBAProjects
              For Each oProject In oProjects
                    If oProject.Name = oProjectName Then
                        ProjectFound = True
                        Exit For
                    End If
                Next
If ProjectFound = False Then
    Call ThisApplication.VBAProjects.Open(ProjectLocation)
    Set oProject = ThisApplication.VBAProjects.Item(ThisApplication.VBAProjects.count)
End If

Call oProject.InventorVBAComponents(oModuleName).InventorVBAMembers(oMacroName).Execute 'module1, macro 2&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Jan 2020 14:25:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ribbon-macro-button-to-call-macro-in-second-ivb-project/m-p/9229363#M68474</guid>
      <dc:creator>cshunt</dc:creator>
      <dc:date>2020-01-03T14:25:38Z</dc:date>
    </item>
  </channel>
</rss>

