Forum Discussion
dodger1
Nov 22, 2022Copper Contributor
MS Ribbon - how to set its visible property to true/false in office programmes?
How can you programatically change the visibility of the ribbon in Excel & Word, and add custom features like shorcuts to macros? Presumably, the 'ribbon' is an Object that has properties and method...
Jan_Wijninckx
Mar 26, 2024Brass Contributor
dodger1
I had exactly the same issue. ChatGPT couldn't solve it either, but gave me plenty of pointers. So that this doesn't go to waste, here a 3 VBA routines that do what the buttons do:
Sub RibbonShowFull()
If Application.CommandBars("Ribbon").Visible Then
Debug.Print "Ribbon is visible, check by how much"
With Application.CommandBars("Ribbon").Controls(1)
If .Height > 40 And .Height < 155 Then
Debug.Print "Shows tabs functions only, toggle"
CommandBars.ExecuteMso "MinimizeRibbon"
End If
End With
Else
Debug.Print "Is not showing, switch Ribbon on"
Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"", True)"
With Application.CommandBars("Ribbon").Controls(1)
If .Height < 155 Then
Debug.Print "Shows tabs functions only, toggle"
CommandBars.ExecuteMso "MinimizeRibbon"
End If
End With
End If
End Sub
Sub RibbonShowTabsOnly()
If Application.CommandBars("Ribbon").Visible Then
Debug.Print "Ribbon is in view, check by how much"
With Application.CommandBars("Ribbon").Controls(1)
If .Height > 155 Then
Debug.Print "Shows full tabs, toggle"
CommandBars.ExecuteMso "MinimizeRibbon"
End If
End With
Else
Debug.Print "Ribbon is hidden, switch on"
Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"", True)"
With Application.CommandBars("Ribbon").Controls(1)
If .Height > 155 Then
Debug.Print "Shows full tabs, toggle"
CommandBars.ExecuteMso "MinimizeRibbon"
End If
End With
End If
End Sub
Sub RibbonHideFromView()
If Application.CommandBars.GetVisibleMso("TabHome") Then
Debug.Print "Ribbon is visible, switch off"
Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"", False)"
End If
End Sub
Hope that helps!
- dodger1Nov 01, 2024Copper Contributor
So sorry not to have responed earlier to you suggestion.
Just been too busy with "things" to explore your idea.
Many thanks
Roger.