ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   protect sheet in VB (https://www.excelbanter.com/excel-programming/306736-protect-sheet-vbulletin.html)

Mark Howard

protect sheet in VB
 
Hi,
I want to use the below line lock a sheet
ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True

and assign a password.

then the macro will hide the sheet.
ActiveWindow.SelectedSheets.Visible = False

Another Macro will unhide the sheet and then unlock it
with a password prompt.
ActiveWindow.SelectedSheets.Visible = False
ActiveSheet.Unprotect
but this does not work. I cannot assign a password on
protecting.

any ideas?



Paul B[_6_]

protect sheet in VB
 
Mark, try this
ActiveSheet.Protect password:="123", DrawingObjects:=True, _
Contents:=True, Scenarios:=True

or with a input box to select a password

pw = InputBox("What password do you want to use ?")
ActiveSheet.Protect password:=pw, DrawingObjects:=True, _
Contents:=True, Scenarios:=True

--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2000 & 97
** remove news from my email address to reply by email **
"Mark Howard" wrote in message
...
Hi,
I want to use the below line lock a sheet
ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True

and assign a password.

then the macro will hide the sheet.
ActiveWindow.SelectedSheets.Visible = False

Another Macro will unhide the sheet and then unlock it
with a password prompt.
ActiveWindow.SelectedSheets.Visible = False
ActiveSheet.Unprotect
but this does not work. I cannot assign a password on
protecting.

any ideas?





Mike Fogleman

protect sheet in VB
 
If you protect with code, and want a password, then the password is set with
code. There will be no prompt to set one.

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

Also, to unhide a sheet use .Visible = True

If someone tries to unprotect the sheet from the menu, they will get a
prompt for the password.

Hope this helps...Mike F


"Mark Howard" wrote in message
...
Hi,
I want to use the below line lock a sheet
ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True

and assign a password.

then the macro will hide the sheet.
ActiveWindow.SelectedSheets.Visible = False

Another Macro will unhide the sheet and then unlock it
with a password prompt.
ActiveWindow.SelectedSheets.Visible = False
ActiveSheet.Unprotect
but this does not work. I cannot assign a password on
protecting.

any ideas?






All times are GMT +1. The time now is 06:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com