How to save and restore cell's locked property

gbrenkman

New Member
Joined
Feb 4, 2017
Messages
5
I have a worksheet that has some locked and unlocked cell, and the worksheet is protected with a password that only I know.

When the user closes/saves the document, I want to prompt if they want to save the file as an "Internal Use Only" file that preserves the status of the locked/unlocked cells. Of course, a normal save will do that.

But I also want to prompt at close/save if they want to save the file as an "External Use Only" file that will be sent outside the company to customers. In that case, I want to set ALL the cells to locked status before the save, so that customers won't be able to change any of the cell values (e.g., quoted prices).

When the file is opened, I want to prompt for a password that only the internal users will know. If the password is entered, code needs to restore the previous locked/unlocked status of the cells so that internal users can again work with the file.

I'm thinking I'd have to loop through all the cells from A1 to LastCell, and perhaps store cell addresses and settings onto a hidden worksheet. Then use those values to reset the locked/unlocked status of the cells if the password is entered upon open. But I'm not sure how to do that, or if there's a better way.

Why not save two versions of file, one with some cells locked/unlocked and others all locked? Well, I suppose that's an option, but if the "internal use" file gets accidentally deleted, then there's no way to recover and have a file where some cells are locked and others unlocked for internal use.

Any ideas/code ideas, folks? Thanks!
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
I want users to be able to save the file.

The worksheet and workbook are protected with a master password only I know.

When I save the file and distribute it to internal users, some cells are locked and others are unlocked. That allows internal users to make changes in the cells I want them to be able to change, but not other cells.

When the internal users go to save the file, I'll put up a user form asking if they want to save an internal or external version. If they pick internal, it just saves the file as is with the mix of locked/unlocked cells. If they pick external, then VBA would set all the cells to locked so that the external users won't be able to change anything.

Upon open, VBA code will show a user form and prompt for a "unlock" code that only internal users will know. If the internal user enters the magic code, then I need VBA to return the cells from ALL locked back to the previous combination of locked/unlocked cells so the internal users again can edit where I want them to but not in cells that I don't want them to change.
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top