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

Calculated Dates

Word makes it easy to insert today's date in a document, but not as easy to insert a date X number of days in the future. ...

Discover More

Converting Units

Using the Analysis ToolPak for the vast conversions the CONVERT function in an Excel worksheet has availabile.

Discover More

Using Text Boundaries

Text boundaries can help you better visualize where text can appear in your document. The feature is easy to turn on and ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (menu)

DOS From Macros

Need to run a DOS command from within one of your macros? The answer is the Shell command, described in this tip.

Discover More

Determining an Integer Value

When creating macros, you often need to process numbers in various ways. VBA allows you to convert a numeric value to an ...

Discover More

Running Macros on Hidden Worksheets

Excel allows you to hide worksheets so that they aren't visible to those using your workbook. Hiding worksheets has 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 six minus 4?

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.