Protecting

kwaring

New Member
Joined
Mar 14, 2002
Messages
49
I've looked, but haven't been able to find the code for unprotecting sheets and workbooks at the beginning of a macro and protecting again at the end. Unfortunately, my help in Excel or VBA isn't installed so I can't look there.
Also I was wondering if there was a way to make it so cells on the sheet cannot be selected (when you protect the sheet you are still able to select cells).
Thank You!
Kyle
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hi,

From recording a macro, the codes for unprotect and protecting a worksheet and workbook are:

ActiveSheet.Unprotect password:="Testing"
ActiveSheet.Protect password:="Testing", DrawingObjects:=True, Contents:=True, Scenarios:=True
ActiveWorkbook.Protect Structure:=True, Windows:=False
ActiveWorkbook.Unprotect

And as for have cells can not be selected, I am hot too sure whether hiding those cells would do the trick. For example, hide the whole column or something, and the having the sheet protected, then users can not edit them.

HTH
 
Upvote 0
On 2002-03-24 19:37, kwaring wrote:
I've looked, but haven't been able to find the code for unprotecting sheets and workbooks at the beginning of a macro and protecting again at the end. Unfortunately, my help in Excel or VBA isn't installed so I can't look there.
Also I was wondering if there was a way to make it so cells on the sheet cannot be selected (when you protect the sheet you are still able to select cells).
Thank You!
Kyle

Try this;

Sub Protect_Noselection()
ActiveSheet.Protect "test", True, True, True
ActiveWorkbook.Protect "test", True, True
ActiveSheet.EnableSelection = xlNoSelection

'=============
'Do your thing
'=============

ActiveSheet.Unprotect "test"
ActiveWorkbook.Unprotect "test"
End Sub





Note XlNoselection will only take effect when the sheet is in protection mode.


Ivan
 
Upvote 0

Forum statistics

Threads
1,214,808
Messages
6,121,686
Members
449,048
Latest member
81jamesacct

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