ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Password protection worksheet (https://www.excelbanter.com/excel-programming/426070-password-protection-worksheet.html)

JulieF

Password protection worksheet
 
I have a worksheet which I require to have password protected. I have set
the password up in the normal way no problem.
I then want users to be able to run a macro to select a custom view, I have
attached the following code to the macro which will allow the view to be run
without requesting a password (if the bit with password isnt in there is does
ask the user to input the password before showing the custom view).
' Sheets("sheet 2"). Unprotect Password = "mypassword"
ActiveWorkbook.CustomViews("2 - Monday View").Show
ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, AllowSorting:=True
Range("L9").Select
Sheets("sheet 2").Protect Password = "mypassword"
End Sub

However, whilst the macro appears to work it doesnt put the password back on
the worksheet. The user can just go to unprotect sheet and click on ok which
is what I need to stop.

any help would be most welcome.



Bernie Deitrick

Password protection worksheet
 
Julie,

You need the correct syntax
Sheets("sheet 2").Unprotect Password:="mypassword"


Sheets("sheet 2").Protect Password:="mypassword"

HTH,
Bernie
MS Excel MVP


"julief" wrote in message
...
I have a worksheet which I require to have password protected. I have set
the password up in the normal way no problem.
I then want users to be able to run a macro to select a custom view, I have
attached the following code to the macro which will allow the view to be run
without requesting a password (if the bit with password isnt in there is does
ask the user to input the password before showing the custom view).
' Sheets("sheet 2"). Unprotect Password = "mypassword"
ActiveWorkbook.CustomViews("2 - Monday View").Show
ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, AllowSorting:=True
Range("L9").Select
Sheets("sheet 2").Protect Password = "mypassword"
End Sub

However, whilst the macro appears to work it doesnt put the password back on
the worksheet. The user can just go to unprotect sheet and click on ok which
is what I need to stop.

any help would be most welcome.






All times are GMT +1. The time now is 07:46 AM.

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