VBA code to protect worksheet, and allow changes to cell comments

Gerald Higgins

Well-known Member
Joined
Mar 26, 2007
Messages
9,258
Hi all, thanks in advance for any help.

I've got some code which protects the worksheet using a password.

I want to allow users to be able to input and edit comments.
It doesn't really matter whether this is restricted to unlocked cells, or
whether they can do it over the entire worksheet.

I can do this manually, and my code works for everything EXCEPT allowing comments to be edited / inserted.

Any ideas what I should be doing differently ?

Here's what I have now...
Code:
ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=True
    ActiveSheet.EnableSelection = xlUnlockedCells
    ActiveSheet.EnableSelection = xlLockedCells
    ActiveSheet.Protect "password"

This does everything I want it to do, EXCEPT allow comments to be edited.
I've tried shuffling things around, but it either does just the same, or prompts for a password unexpectedly.
From the macro recorder, I've worked out that DrawingObjects has to be set to False for comments, but it doesn't seem to work when I put it all together.

Using 2003....
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Hi Gerald,

No well tested, but maybe:
Sheet1.Protect Password:="MyPassword", DrawingObjects:=False, Contents:=True, Scenarios:=True
 
Upvote 0
Thanks for the input GTO but that wasn't it.
Specifically, I tried
Code:
    ActiveSheet.Protect Password:="password", DrawingObjects:=False, Contents:=True, Scenarios:=True
    ActiveSheet.EnableSelection = xlUnlockedCells
    ActiveSheet.EnableSelection = xlLockedCells
    ActiveSheet.Protect "password"

and

Code:
    ActiveSheet.Protect "password", DrawingObjects:=False, Contents:=True, Scenarios:=True
    ActiveSheet.EnableSelection = xlUnlockedCells
    ActiveSheet.EnableSelection = xlLockedCells
    ActiveSheet.Protect "password"

and they both seem to do the same - turn protection on, but not allow changes to comments.

Any more ideas ?
 
Upvote 0
Okay, I do not think you need the second .Protect.

Here appears to be the problem though: xlLockedCells does not exist as a constant in 2003.

I would suggest that if you do not use Option Explicit, you may wish to consider it, as these type issues are avoided.

I used:
Rich (BB code):
    ActiveSheet.Protect Password:="password", DrawingObjects:=False, Contents:=True, Scenarios:=True
    ActiveSheet.EnableSelection = xlNoRestrictions
End Sub
and all appears well.

Does that help?

Mark
 
Upvote 0

Forum statistics

Threads
1,224,520
Messages
6,179,270
Members
452,902
Latest member
Knuddeluff

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