Register  Login
Snippets & Tips
***NEW CUSTOMER OFFER***
Get 15 minutes of free Live Help!
Coupon Code: 20110729  
Live Help
Search Snippets & Tips Minimize
  

Notes

Some operating systems block files that come from other computers.  If you cannot get a downloaded file to work properly, right-click over the file, select the Properties option, and then click the Unblock button at the bottom of the General tab.

  

View Code Snippets & Tips Minimize
Nov 27

Written by: Extra Mile Data
11/27/2009 2:27 PM 

If you've ever wished you could keep the Office Ribbon, but automatically minimize it to conserve space, this VBA function is for you.  The same technique works for Microsoft Access, Microsoft Word, etc.

The function includes two pieces of logic.  The first piece checks to see whether or not the ribbon is currently minimized by examining its current height.  Once that it determined, the second piece determines whether or not to toggle the visibility of the Ribbon.  If it needs to toggle, it sends a Ctrl-F1 using the SendKeys statement.  In the SendKeys statement, it uses a Wait argument of True to force the code to halt until the keys have been processed.  It may not work otherwise.

You do not need to pass an argument to the function if you want to minimize the Ribbon.  You may use the function in the opposite manner (maximize the Ribbon if it is minimized) by passing the function an argument of False.

To use the function in MS Access to conserve space for a form when it opens, be sure to call the function before opening the form.  You can do that with a macro, where the first action is to call the function and the next action is to open the form.  Calling the function in the Open or Load event of the form is too late; the height of the form has already been determined before those events run.

Code:

Public Function MinimizeRibbon(Optional MakeMin = True)
' This function minimizes or maximizes the ribbon, depending upon the value
' of MakeMin.  True minimizes the ribbon and False maximizes the ribbon.
' The default value for MakeMin is True.

' MinimizeRibbon() Version 1.0.0
' Copyright © 2009 Extra Mile Data,
www.extramiledata.com.
' For questions or issues, please contact
support@extramiledata.com.
' Use (at your own risk) and modify freely as long as proper credit is given.
On Error GoTo Err_MinimizeRibbon

    Dim blnIsMin As Boolean
   
    ' The Ribbon has a height of 147 when it is maximized.
    ' If it is maximized, set the blnIsMin value to False.
    If Application.CommandBars.Item("Ribbon").Height = 147 Then
        blnIsMin = False
    Else
        blnIsMin = True
    End If
   
    ' If the current state is the same as MakeMin, then do
    ' nothing.  Otherwise, toggle the ribbon by using Ctrl-F1.
    If MakeMin = blnIsMin Then
        ' Do nothing.
    Else
        ' Send the keystrokes and wait until they are processed.
        SendKeys "^{F1}", True
    End If

    MinimizeRibbon = True

Exit_MinimizeRibbon:
    On Error Resume Next
    Exit Function

Err_MinimizeRibbon:
    MsgBox Err.Number & " " & Err.Description, vbCritical, "MinimizeRibbon"
    MinimizeRibbon = False
    Resume Exit_MinimizeRibbon

End Function


Download Code: basMinimizeRibbon.zip

Tags:

4 comment(s) so far...

Re: How to use VBA to minimize the Office 2007 Ribbon

You do realize that you can just double click the bugger and it shrinks up....do you?

goodness sometimes vba code is overused

By isaac on   2/12/2010 12:30 PM

Re: How to use VBA to minimize the Office 2007 Ribbon

Yes, I am aware that a single-click will minimize/maximize the Ribbon temporarily and a double-click will fix it in place as minimized or maximized. Sometimes it is enough to train my database users to take advantage of that feature. Other times, the combination of a maximized ribbon and a tall form may resize the form when it opens so that not all of the form is visible to the user. I would prefer that the user see all of the form if possible when it opens, so I use some VBA code to ensure that the ribbon is minimized before the form opens.

By Extra Mile Data on   2/12/2010 12:30 PM

Re: How to use VBA to minimize the Office 2007 Ribbon

Instead of testing for the height of the ribbon you can simply check the "visible" property (because the height of the ribbon is different depending on environment):

If Application.CommandBars.Item("Ribbon").visible = true Then

By Stefan on   10/21/2011 11:50 AM

Re: How to use VBA to minimize the Office 2007 Ribbon

My understanding is that the Visible property determines whether or not a command bar is visible, not whether or not it is minimized. My code above keeps the ribbon visible, but reduced in size.

By Extra Mile Data on   10/21/2011 11:52 AM

Your name:
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
CAPTCHA image
Enter the code shown above in the box below
Add Comment   Cancel 
  

Extra Mile Data - Go Faster...Go Further!

Go Faster...Go Further!  Call (479) 524-8479.
Extra Mile Data, your source for Microsoft Access help

Terms Of Use | Privacy Statement | © 2003-2011 Extra Mile Data