- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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?
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.
using something like "VbaProject2.addbuttontoribbon.MyMessage" doesn't seem to work.
Any ideas would be welcomed. Thanks!!
The tree starts out like this:
ApplicationProject (Default.ivb)
VbaProject 2 (VbaProject2.ivb)
-addbuttontoribbon
Sub MyMessage()
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
Solved! Go to Solution.
