PDA

View Full Version : Solved: Password protection for Macro enabled sheet



nagavineela
09-18-2010, 01:34 AM
Hi,
I have a workbook with 2 sheets. Each sheet has 5 macro assigned buttons.
How do i protect sheet?
When i click on any of the macro assigned button should not ask for password sametime should not allow user to edit excel rows and columns.
To edit manually, when we right click on sheet name tab -> unprotect sheet should prompt for "password".

Please help me at the earliest.

Thanks

Bob Phillips
09-18-2010, 03:03 AM
Just password protect it and add code in the macros to unprotect it and re-protect it.

nagavineela
09-18-2010, 03:07 AM
Hi XLD,
Thank you. The following is the syntax I used to protect and unprotect

Public Sub Workbook_Open()
Sheets("General Inst.-GroundFixed").Protect Password:="password", DrawingObjects:=True, Contents:=True, Scenarios:=True

and
Sub UnprotectAllSheets()
Dim wSht As Worksheet
For Each wSht In ThisWorkbook.Worksheets
wSht.Unprotect ("password")
Next wSht
End Sub

in Thisworkbook.

If I go and right click on the sheet name of excel and unprotect it is not asking for password.

Please help me.

Thanks,

Bob Phillips
09-18-2010, 03:38 AM
Then that suggest it doesn't have a password doesn't it?

nagavineela
09-18-2010, 03:40 AM
Yes.
Where should i place the code to protect with password and unprotect with password. I mean in Sheet1() or 'thisworkbook' etc.
Please guide me

Bob Phillips
09-18-2010, 10:47 AM
In the button macros I would suggest.

nagavineela
09-19-2010, 08:54 PM
Hi XLD,
Thank you very much. Its working after adding the password protection in each button macros.

Regards,