VBA Ribbon and Sheetactivate

57 views Asked by At

I have a workbook with personal Ribon Tab

====== "customTab"

etc.

I would like this ribbon tab to be activated systematically when activating a sheet in the workbook, so that even if the user temporarily uses another ribbon tab, my custom tab is reactivated when switching to a sheet.

Despite all my research I haven't found a solution.

Thank you for help

Philippe

1

There are 1 answers

0
phmauber On

yes I already have a ribbon whose code starts with:

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui"
      onLoad="ribbonLoaded">
  <ribbon>
 <tabs>
 <tab id="customTab" label="DA2023" insertBeforeMso="TabHome">
  <group id="Navig" label="navigation">

For the VBA:

`Public myRibbon As IRibbonUI


'Callback for customUI.onLoad
Sub ribbonLoaded(ribbon As IRibbonUI)
    Set myRibbon = ribbon
End Sub

`

And:

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
 'Activate DA2023 ribbon
 On Error GoTo errhandle
 myRibbon.ActivateTab "customTab"
 Exit Sub
 errhandle:
 MsgBox "the DA2023 ribbon tab could not be displayed normally" &       Chr(13) & _
"If this error is continuous....." & Chr(13) & _
"Try to save the file, then open it again", vbCritical
 On Error GoTo -1

End Sub

BUT I have to deal with an error, because regularly calling the tab display causes an error.

Sincerely

THANKS