Written by Allen Wyatt (last updated September 26, 2025)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, 2021, and Word in Microsoft 365
Donna is in charge of preparing a document that will be used throughout her company. She would like the document, when opened, to "minimize" the ribbon at the top of the screen and then, when closed, return the ribbon to its "pre-opening" state. This would be done to provide the maximum screen area for the document. Donna figures that this will take a macro to accomplish, but she's not sure which commands to use to accomplish the task.
There is an amazing shortage of information available on working with the ribbon in VBA. In fact, the only method we've been able to locate that will minimize the ribbon is the following:
ActiveWindow.ToggleRibbon
This method is the same as pressing Ctrl+F1. It toggles the ribbon, changing it from maximized to minimized, and vice-versa. This, of course, is not what Donna wants to do; she wants to make sure it is minimized. Using the ToggleRibbon method, you can "fudge" a way to figure out whether the ribbon is minimized or not. Consider the following example macros.
Dim w As Variant
Dim h1 As Long
Dim h2 As Long
Dim StartedWithRibbon As Boolean
Private Sub Document_Open()
Set w = ActiveWindow
h1 = w.UsableHeight
w.ToggleRibbon
h2 = w.UsableHeight
If h1 < h2 Then
StartedWithRibbon = False
Else
StartedWithRibbon = True
w.ToggleRibbon
End If
End Sub
Private Sub Document_Close()
Set w = ActiveWindow
h1 = w.UsableHeight
w.ToggleRibbon
h2 = w.UsableHeight
If h2 < h1 Then
If StartedWithRibbon Then w.ToggleRibbon
Else
If Not StartedWithRibbon Then w.ToggleRibbon
End If
End Sub
There are actually two macros here, one automatically triggered when a document is opened and the other triggered when it is closed. The macros check the height of the active window, storing it in the h1 variable. It then toggles the ribbon and again checks the active window height, storing it in h2. By comparing the two values, you can determine whether the ribbon is minimized or not and then act accordingly.
Note:
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (8515) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, 2021, and Word in Microsoft 365.
Create Custom Apps with VBA! Discover how to extend the capabilities of Office 365 applications with VBA programming. Written in clear terms and understandable language, the book includes systematic tutorials and contains both intermediate and advanced content for experienced VB developers. Designed to be comprehensive, the book addresses not just one Office application, but the entire Office suite. Check out Mastering VBA for Microsoft Office 365 today!
Need to rename a disk file from within a macro? You can do it using the Name command, described in this tip.
Discover MoreDon't want a particular macro to be visible in the Macros dialog box? Once you understand the criteria that Word uses ...
Discover MoreIf you write a macro that makes changes to a document, you may want that macro to save those changes. There are several ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
2022-03-21 12:41:31
Paul
Very clever!
Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.
Visit the WordTips channel on YouTube
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2025 Sharon Parq Associates, Inc.
Comments