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.

Using Macros in Protected Workbooks

by Allen Wyatt
(last updated March 29, 2016)

6

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.

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.

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

Automatically Updating Fields and Links

You can update fields and links automatically when you print your document, but what if you want them updated when you open ...

Discover More

Using Alternating Styles

Alternating styles can come in handy when you have to switch between one type of paragraph and another, automatically, as you ...

Discover More

Viewing Your Custom Styles

If you develop a set of preferred styles, you may want to use those styles with a document you receive from someone else. ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (menu)

Saving a Workbook Using Passwords

One of the security features built-in to Excel is the ability to save a workbook using a password that limits access to the ...

Discover More

Protecting an Entire Folder of Workbooks

Want to protect the Excel information stored in a particular folder on your system? There are a number of ways you can ...

Discover More

Automatically Protecting After Input

Do you want user-entered data to be immediately protected so that it cannot be changed? This can be done relatively easily ...

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}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 8Mpixels. 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 5 + 0?

2017-06-17 20:46:32

Tashiba

But what if the sheet is not mine to unprotect? I have about 2k plus codes and there descriptions that are on the protected sheet that I need to extract. So far I'm having to do this one by one. Please Help!!


2016-12-14 11:15:13

Rick Stockstill

Hello,

Excellent example... exactly what I needed !!

Till later,
Rick S.
San Antonio, TX


2015-08-27 01:48:38

raihan

i want to know how enable macro username and password input in aexcel file


2015-05-08 02:09:05

jon

Is anyway to bypass the limitation of the shared workbook? I have one workbook with macro enabled which extract data from database and run calculation. I want to make the file shared as I need more than one user to have their inputs as inputs as my calculation run by Macro.


see my blog http://www.computerzero.com


2015-01-19 19:17:01

Nephi Safford

Update to Office 2010 SP2 and the problem goes away.


2014-12-08 22:16:22

Petros

I accidentally discovered a simple trick to make VBA viewable in Shared Workbooks. You can now edit, record or create new macros in a shared workbook. Read more:

http://www.spreadsheet1.com/move-excel-vba-projects-from-one-workbook-to-another.html


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.