
Tips.Net > ExcelTips Home > Macros > VBA Examples > Controlling Display of Toolbar Buttons
Summary: This tip contains a macro that will enable custom toolbar buttons whenever a worksheet is visible. (This tip works with Microsoft Excel 97, Excel 2000, Excel 2002, and Excel 2003.)
Jody Perrell 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.
Tip #2618 applies to Microsoft Excel versions: 97 2000 2002 2003
Got the Time? Understanding the ins and outs of working with times and dates can be confusing. Remove the confusion--ExcelTips: Times and Dates is an invaluable resource for learning how best to work with times and dates.
Check out ExcelTips: Times and Dates today!
Have thousands of ExcelTips at your fingertips, on your own system. Answer your own questions or help support others. (more information...)
Ask an Excel Question
Make a Comment
ExcelTips FAQ
ExcelTips Premium
Bugs and Pests Tips
ExcelTips
Family Tips
Health Tips
Home Tips
Organizing Tips
WordTips
Advertise on the
ExcelTips Site