Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Using Macros in Protected Workbooks.
Written by Allen Wyatt (last updated April 3, 2021)
This tip applies to Excel 97, 2000, 2002, and 2003
Lori had a problem with a workbook she wanted to share with others. The workbook contained a macro, but whenever the workbook is protected to prevent others from making changes to the workbook, Lori reports that "the macro is disabled."
Lori's exact problem is a little hard to reproduce, as testing shows that macros are still available in both protected worksheets and protected workbooks. You can still display the Macros dialog box and see the list of available macros. You can still choose one of the macros and run it.
Of course, seeing and running the macros may not be Lori's problem; it could be that the macro fails to run correctly when used on a protected worksheet. If that is the case, the problem typically only crops up if the macro is attempting to perform some action that violates the protection applied to the worksheet. For instance, if the protection doesn't allow for rows or columns to be deleted and the macro tries to do such, then it won't work.
The solution in this case is to modify your macro so that it unprotects the worksheet before making its changes. The following shows the basics of how this is done:
Sub ModifyProtectedSheet() ActiveSheet.Unprotect password:="yourpassword" 'work on the worksheet here ActiveSheet.Protect password:="yourpassword", _ DrawingObjects:=True, Contents:=True, Scenarios:=True End Sub
The first line of this example unprotects the worksheet, you can then perform your processing, and then the last line again protects it. If your workbook uses protection, then the same technique can be used with the workbook—unprotect it, then make changes, then reprotect it.
Lori's problem could also be related to the word "sharing," which she used in her problem statement. If, by sharing, Lori means using Share Workbook to make the workbook "sharable" by others, then you will see a warning when sharing is activated. The warning indicates that macros cannot be "viewed or edited" in shared workbooks. This does not, however, mean that the macros are disabled, since you can still display the Macros dialog box to see a list of macros and choose one to run. You cannot, however, display the VBA Editor and look at the actual macro code.
Finally, there are some features of Excel that are simply disabled in shared workbooks. If your macro tries to perform any of these disabled actions, it won't work properly. This is a limitation of Excel, and there is nothing that can be done about it. (For more information on what cannot be done in a shared workbook, use the online help system and search for "shared workbooks, limitations.") The only way around these limitations is to not share the workbook.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2833) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Using Macros in Protected Workbooks.
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!
Want to protect the Excel information stored in a particular folder on your system? There are a number of ways you can ...
Discover MoreOne of the security features built-in to Excel is the ability to save a workbook using a password that limits access to ...
Discover MoreDo you want user-entered data to be immediately protected so that it cannot be changed? This can be done relatively ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2021-11-20 04:19:31
Glenn Williams
Sorry the "s" fell off. It should have read "Hi Guys"....
2021-11-20 04:17:52
Glenn Williams
Hi Guy,
How do you stop a macro from running on a protected worksheet.
I want to disable three buttons and leave only one button that will run a macro.
I basically have buttons that show an extended data view, one that hides a lot of the extended data, one that protects the work sheet and the other one unprotects the work book when you enter the password. I only want the last one to run when the sheet is protected at the moment the first three run when the sheet is protected.
Thanks for any thoughts you may have.
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments