Re-applying sheet protection

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re-applying sheet protection

Post by ABabeNChrist »

I have a few worksheets within the same workbook that have protection that protect links and formatted text. There can be times that when a sheet needs to be unprotected to make modification or changes to the sheet, at that point I would right click on sheet name at bottom, and then select unprotect, that’s parts OK. The protection is used to help prevent any BOO BOO’S. Can I use this code below to add protection to sheet, even though sheet is already protected, or do I need to add something. It seems to work OK, I just don’t want it to be an issue later on. And which approach is better to add code at the closing of sheet or opening.

Code: Select all

ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=True, Password:=""

User avatar
HansV
Administrator
Posts: 78437
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Re-applying sheet protection

Post by HansV »

It doesn't hurt if you protect an already protected sheet.
Neither will you have problems if you try to unprotect an already unprotected sheet.

BTW if you protect a sheet with

ActiveSheet.Protect UserInterfaceOnly:=True

you can still modify the sheet using VBA without unprotecting and reprotecting it.
Best wishes,
Hans

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Re-applying sheet protection

Post by ABabeNChrist »

Hi HansV
Using "UserInterfaceOnly:=True" how is this different than just an unprotected sheet

User avatar
HansV
Administrator
Posts: 78437
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Re-applying sheet protection

Post by HansV »

The sheet will act as a protected sheet to the end user - only unlocked cells can be edited, and many formatting features will be disabled. But for a VBA macro, the sheet will act as if it's unprotected - all cells can be changed, etc.
Best wishes,
Hans

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Re-applying sheet protection

Post by ABabeNChrist »

Thanks HansV
I checked it out and your right, it acted just as if I had protection, Cool
I enjoy learning new things