Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Using Macros in Protected Workbooks.
Written by Allen Wyatt (last updated April 20, 2024)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021
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 (12570) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. You can find a version of this tip for the older menu interface of Excel here: Using Macros in Protected Workbooks.
Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!
Need to select a range of cells in a column? This tip can help, as it shows how to select from a specific cell all the ...
Discover MoreBesides the regular way of displaying formulas, Excel can also display them using what is called R1C1 format. If you are ...
Discover MoreEver want to have Excel run a procedure whenever you open a workbook? It's not as difficult as you might think. Here's how.
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2024-04-20 11:21:51
J. Woolley
For related discussion:
https://excelribbon.tips.net/T010282_Using_a_Protected_Worksheet.html
https://excelribbon.tips.net/T009639_Visually_Showing_a_Protection_Status.html
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu 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