10

How to Auto-hide Ribbon in Excel 2013 in VBA? I would like to achieve exactly what I get by clicking on the upper arrow icon at the right top of Excel menu marked with blue in the picture below and then clicking on the first option marked with orange:

enter image description here

I would be also interested in VBA switching back to the third option Show Tabs and Commands. Important thing for me is to keep in the Excel menu the upper arrow icon (marked with blue).

I have tried hints shown in this thread: VBA minimize ribbon in Excel but I am not satisfied with results.

Attempt 1

Application.ExecuteExcel4Macro "Show.ToolBar(""Ribbon"",False)

This is good but hides the blue icon.

Attempt 2

CommandBars.ExecuteMso "MinimizeRibbon"

This is close to what I want. This keeps the blue icon but does not hide the entire menu. It switches to the second option displayed in the picture Show Tabs.

Attempt 3

SendKeys "^{F1}"

The attampt does not work at all. Moreover, it is supposed to imitate the attempt 2. So even that would not satisfy me.

0

7 Answers 7

14
+50

I can't see that anyone else has brought this up... This isn't a workaround, this is the actual idMSO for what I think you're looking for. This code makes my excel window look like everything is gone the same way the first option does for Auto-Hide Ribbon.

Before the code runs, my window looks like this, in the 'Restore' size:

enter image description here

Running the following code:

Sub HideTheRibbon()
    CommandBars.ExecuteMso "HideRibbon"
End Sub

Will make your window look like this, in the maxamized window size (just like what would happen if you were to press the Auto-Hide Ribbon button manually):

enter image description here

If you want the ribbon automatically hidden when the workbook opens, put this in the workbook code:

Sub Workbook_Open()
    CommandBars.ExecuteMso "HideRibbon"
End Sub

Alternatively, to achieve the same thing, you could put this code in a module:

Sub Auto_Open()
    CommandBars.ExecuteMso "HideRibbon"
End Sub

If you want the window to revert back to normal, you run the exact same code again. In other words, the following code would make no visual change at all when ran because the idMSO "HideRibbon" is a toggleButton:

Sub HideTheRibbon()
    CommandBars.ExecuteMso "HideRibbon"
    CommandBars.ExecuteMso "HideRibbon"
End Sub

If you want a full list of all the idMSO in excel, click the following that apply to you: Excel 2013+, Excel 2010, Excel 2007

3
  • I am happy you have come up with this solution. Simple and works:-) Sep 5, 2016 at 9:42
  • Great solution. Aug 4, 2017 at 15:45
  • Turned out that (at least Excel 2016) needs Application.CommandBars.ExecuteMso "HideRibbon" if the code is not used in a module.
    – Pᴇʜ
    Oct 30, 2018 at 16:13
8

I use this for presentation purposes

ActiveWindow.DisplayGridlines = False

ActiveWindow.DisplayHeadings = False

Application.DisplayFormulaBar = False

Application.DisplayFullScreen = True This is what i used to hide the ribbon

1
  • 1
    Instread of accepted answer stackoverflow.com/a/39310260/375368 the DisplayFullScreen parameter is working without changing the real MainWindow. This answer is working more proper to me. Working in Office 16 with Excel.
    – Nasenbaer
    Aug 23, 2018 at 8:56
5

Probably you should do something a little more complicated:

Use CommandBars.ExecuteMso "MinimizeRibbon" to show/hide the ribbon. Depending on what you want, you may show/hide all other tabs in the ribbon. E.g. use something of the code here -> Excel Hide/Show all tabs on Ribbon except custom tab

Thus 2 steps:

Step 1 - show or hide with the CommandBars.ExecuteMso

Step 2 - show or hide the rest of the tabs with some macros from the link.

A little big workaround, but you will get what you want.

2
  • In the link there are enough. But still, explicitly - here -> rondebruin.nl/win/s2/win012.htm. The idea is to make sure, that whenever the "CommandBars.ExecuteMso MinimizeRibbon" is called, you call for some additional macro (step2), which hides or shows all the tabs. Mr. De Bruin has explained it really well. Hope to have help you :)
    – Vityata
    Aug 31, 2016 at 12:33
  • 1
    Your answer is very useful for building custom ribbon and may lead to the goal. Although provided links explain ribbon building clearly, I am happy that there is a simple solution mentioned by Tyeler. If Tyeler did not reveal his solution, the bounty would be yours. Thank you. Sep 5, 2016 at 9:31
4

I call this macro on Workbook_Open to check for the ribbon and if not hidden, it will hide the ribbon (I actually have it located in another Sub that also removes the formula bar, status bar, headings, and gridlines at Workbook_Open)...

Sub HideRibbon()
If CommandBars("Ribbon").Controls(1).Height < 100 Then
Exit Sub
Else
    CommandBars.ExecuteMso ("MinimizeRibbon")
End If
End Sub

Then I call this macro on Workbook_BeforeClose to check for the ribbon and if it is not shown, it will show the ribbon for the next excel spreadsheet that is opened.

Sub ShowRibbon()
If CommandBars("Ribbon").Controls(1).Height > 100 Then
Exit Sub
Else
    CommandBars.ExecuteMso ("MinimizeRibbon")
End If
End Sub

This eliminates the chance of hiding the ribbon when the workbook is opened and a user then manually showing the ribbon which in turn would reverse the show on close and actually hide the ribbon. On open, the ribbon would then be shown again. This will keep it the same every time on open and close of the workbook.

3

Give this a try:

Sub ShowHideRibbon()

If CommandBars("Ribbon").Controls(1).Height < 100 Then
    CommandBars.ExecuteMso ("MinimizeRibbon")
Else
    CommandBars.ExecuteMso ("MinimizeRibbon")
End If

End Sub

Or this:

Sub ShowHideRibbon1()

If Application.ExecuteExcel4Macro("Get.ToolBar(7,""Ribbon"")") Then
    Application.ExecuteExcel4Macro "Show.ToolBar(""Ribbon"", False)"
Else
    Application.ExecuteExcel4Macro "Show.ToolBar(""Ribbon"", True)"
End If

End Sub
1
  • Not this way. The first Sub leads exactly to results of Attempt 2 and the second Sub leads exactly to results of Attempt 1. I have not been happy with any of them. Sep 5, 2016 at 9:38
1

First, go to the Excel Options, and go to "Quick Action Toolbar".

From there, search for "Hide Ribbon" and add to the toolbar. After it's on the QAT, you can call it quickly with ALT+# (on my computer it's the 8th thing, so ALT+8 will auto-hide).

enter image description here

Then just add a sub that does SendKeys ALT then 8:

Sub Macro1()
ActiveSheet.Activate
'Cells(1, 1).Select
SendKeys "%0", True
SendKeys "8", True

End Sub

Note: I know it's silly to have ActiveSheet.Activate, I just added that to test the macro. Depending on how it's being called, you can remove/comment out that line. The % is equivalent to ALT, and technically, I have to press 0 then 8, hence the two lines.

3
  • 1
    Thank you for this idea. Since there is such a native "button" in Excel commands - is it not possible to call it without send keys? Your idea is good trick but it cannot be done by send keys on other users comps - not unless they modify their Quick Action Toolbar. Aug 31, 2016 at 17:53
  • 1
    @PrzemyslawRemin - Hm, good point about the other users. I'm sure there's some way to get it, but you're right, the couple of VBA commands you did find don't quite do it. For what it's worth too, using the MacroRecorder doesn't help - it doesn't track you hiding the ribbon :/
    – BruceWayne
    Aug 31, 2016 at 18:04
  • Just about everything on the list of commands you have shown in your picture use the same words and format (without spaces) as their idMSO. Refer to the links at the bottom of my answer and you can get the full lists to compare them if you'd like.
    – Tyeler
    Sep 3, 2016 at 20:29
1

To get this code to work in excel 2016 you will need the following code in the "ThisWorkbook" mode.

Credit goes to BigBen - not me

Private Sub Workbook_Open()
application.CommandBars.ExecuteMso "HideRibbon"
End Sub

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.