vba solution for protection

  • Thread starter Thread starter danial mansoor
  • Start date Start date
D

danial mansoor

i ve a question is that,i placed a command button in my worksheet wat
i want of i pressed the command button that particular sheet should be
protected with 123 password?

i want to clear here i used recording macro but it just protect sheet
not remember the password 123 is there a way sheet remember the
password?

i also wanted to know is there a way to disable ribbon?or some part of
the ribbon like protect sheet?


is there any guy who can give me better solution for this?
 
Add the password to that .protect line:

Activesheet.protect password:="123"

and if/when you want to unprotect the sheet, it's almost the same:

activesheet.unprotect password:="123"

In fact, since you're running this code from a commandbutton placed on the
worksheet, you can use Excel's Me keyword. Me represents the object that owns
the code -- in this case it's the worksheet.

Me.protect password:="123"
and
Me.unprotect password:="123"
 
Add the password to that .protect line:

Activesheet.protect password:="123"

and if/when you want to unprotect the sheet, it's almost the same:

activesheet.unprotect password:="123"

In fact, since you're running this code from a commandbutton placed on the
worksheet, you can use Excel's Me keyword.  Me represents the object that owns
the code -- in this case it's the worksheet.

Me.protect password:="123"
and
Me.unprotect password:="123"

i used that before

activesheet.Protect Password:="123"

but it didnt work for me

i also used ur solution Me.Protect Password:="123" but it is giving me
error "invalid use of me keyword"

can u suggest me how can i achieve my result to protect sheet with
"123" password when i press comand button.?
 
Why didn't it work for you? You may want to share a few details of how it failed.

If your code is in the sheet module -- you said you used a commandbutton on a
sheet and that's where the code would go -- then the me.protect suggestion
should work.


On 10/03/2010 07:56, danial mansoor wrote:
 
Back
Top