Controlling Display of Toolbar Buttons

Written by Allen Wyatt (last updated July 1, 2023)
This tip applies to Excel 97, 2000, 2002, and 2003


Jody is in the process of developing custom toolbar buttons and assigning macros to the buttons. She wants to have the buttons be enabled whenever at least one worksheet is visible, but is grasping for the proper code to handle such a situation.

There are many ways that this can be approached, as one might assume with an environment as diverse as Excel. One possible solution is to create a routine that simply checks if there are any visible windows on the screen. If there are, then the toolbar buttons can be enabled; if there aren't, then they can be disabled. The following macro will do just that:

Sub CheckButtons()
    Dim bOneOpen As Boolean
    Dim I As Integer
    Dim J As Integer
    
    bOneOpen = False
    For I = 1 To Workbooks.Count
        For J = 1 To Workbooks(I).Windows.Count
            If Workbooks(I).Windows(J).Visible Then bOneOpen = True
        Next J
        If bOneOpen Then Exit For
    Next I
    If bln Then
        'enable buttons
    Else
        'disable buttons
    End If
End Sub

Notice the two comments near the bottom of the macro. All you need to do is replace those comments with the appropriate code to enable or disable your toolbar buttons. (The code will vary, depending on the number and configuration of your buttons.)

This macro can be called either manually, or it can be called from any of the events that are triggered by window changes, such as those that fire when windows are opened, resized, minimized, maximized, or restored.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2618) applies to Microsoft Excel 97, 2000, 2002, and 2003.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Developing Reciprocal Conversion Formulas

When converting between measurement systems, you might want to use two cells for each type of measurement. Make a change ...

Discover More

Creating a CSV File

Need to get your data into a format that can be easily read by other programs? Chances are good that a simple CSV file ...

Discover More

Converting a Table into Text

Word includes a powerful table editor that allows you to create and work with tables easily. At some point, however, you ...

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

More ExcelTips (menu)

Running a Procedure when a Workbook is Opened

Ever want to have Excel run a procedure whenever you open a workbook? It's not as difficult as you might think. Here's how.

Discover More

Determining the Current Directory

When you use a macro to do file operations, it works (by default) within the current directory. If you want to know which ...

Discover More

Counting Cells with Text Colors

Got a bunch of cells that have different colored text in them? Here's a great way to count the occurrences of certain ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is one less than 9?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.