Fixing Macro Button Behavior in Protected Worksheets

Written by Allen Wyatt (last updated October 10, 2020)
This tip applies to Excel 97, 2000, 2002, and 2003


Robin asked a question concerning an oddity in Excel. She creates a worksheet that contains a button drawn using the Forms toolbar, and assigns a macro to the button. The button works fine until the worksheet is protected, then the entire top section of the worksheet acts as a button. (The hand icon appears no matter where you move the mouse, and when you click the macro executes—you don't have to click on the button itself.)

The problem does not occur with all items from the Forms toolbar, but only occurs under certain circumstances. It primarily occurs because a macro button is associated with a cell (such as cell B2), and then the cell is deleted. This means the button is essentially "unattached," so Excel is confused as to where the button belongs. When the worksheet is protected, Excel acts oddly because it believes that the button is "everywhere" since it doesn't really know where the button belongs.

The obvious solution is to make sure that the macro button is always attached to a cell that doesn't get deleted. Unprotect the workbook, select the sliver of the button near the column headers, and move it to a cell you want to associate it with. Reprotect the worksheet and the odd behavior should disappear.

If you cannot see the button that is causing the problem, it could be because it is too small. The solution to that situation is to run a macro that searches for all the buttons in the worksheet and makes them visible. On the unprotected worksheet, run the following:

Sub CheckShapes()
    Dim myShape As Shape
    For Each myShape In ActiveSheet.Shapes
        With myShape
            If .Height < 2 Then .Height = 20
            If .Width < 2 Then .Width = 20
        End With
    Next myShape
End Sub

The macro steps through all the shapes in the worksheet and, if they have a height or width less than 2 pixels, increases their height and width so they are visible. Now you should be able to see the macro button and can drag it to a location on the worksheet or delete it.

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 (2830) 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

Understanding Font Styles

Fonts, by default, come with one or more styles that define variations of how that font is displayed in your document. ...

Discover More

Context Menus, Spell Checking, and Common Tasks

Automatic Spell Checking can change your menu options.

Discover More

Limiting Lines in a Table Cell

When creating tables, Word automatically sets the size of the cells. But what if you want to make sure each cell is a ...

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 Macro When a Worksheet is Deactivated

You can easily configure Excel so that it runs a specific macro whenever a worksheet is deactivated. Just follow the easy ...

Discover More

Deleting a File in a Macro

Macros give you a great deal of control over creating, finding, renaming, and deleting files. This tip focuses on this ...

Discover More

Finding Other Instances of Excel in a Macro

When processing information using a macro, you may need to know if there are any other instances of Excel running on a ...

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 1 + 1?

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.