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

Paragraph Numbers in Headers or Footers

If your documents routinely use numbered paragraphs, you may want to place the number of the page's first paragraph in ...

Discover More

Merging Only a Date from Access

When you are merging data from an Access database, you may get more information than you want, especially when it comes ...

Discover More

Counting All Graphics

Need to know how many graphics a document contains? Getting at the true number may take a little more work than it first ...

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

More ExcelTips (menu)

Deriving an Absolute Value in a Macro

Need to figure out an absolute value within your macro code? It's easy to do using the Abs function, described in this tip.

Discover More

Understanding the If ... End If Structure

One of the most basic of programming structures is the conditional structure: If ... End If. This tip explains how this ...

Discover More

Documenting Changes in VBA Code

Your company may be regulated by requirements that it document any changes to the macros in an Excel worksheet. Your ...

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 two more than 7?

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.