Search code examples
excelvbatags

VBA TAG RIBBON ACTIVATE on event


I would like to enable custom tabs based on the activated sheets. So I have an event macro at the workbook level.

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    tabActivate objRibbonDyn
End Sub

The ribbon was previously declared as an object during the ribbon onload procedure

I planned the following procedure to activate my ribbon tabs, but vba gives me an error: variable.. Type incompatibility

Sub tabActivate(ByVal control As IRibbonControl)

Select Case ActiveSheet.Name

    “Sheet1” box
        objDynRibbon.ActivateTab (“Custom Tab2”)
    “Sheet2” box
        objDynRibbon.ActivateTab (“Custom Tab3”)
    “Graph1” box
        objRibbonDyn.ActivateTab ("OngTB0l")
        
End Select

End Sub

I tried to obtain solutions with Bing AI (GPT4), but its knowledge is not yet at human level :-)

Thank you for a solution or possible solution.

Sincerely


Solution

  • after a night of reflection, I think it is useless to pass a parameter to the procedure.

    
    Sub tabActivate()
    
    Select Case ActiveSheet.Name
    
         “Sheet1” box
             objDynRibbon.ActivateTab (“Custom Tab2”)
         “Sheet2” box
             objDynRibbon.ActivateTab (“Custom Tab3”)
         “Graph1” box
             objRibbonDyn.ActivateTab("OngTB0l")
            
    End Select
    
    End Sub
    
    

    the parameter useful for activatetab is passed in the case occurrences...and i Try this afternoon and it s ok