PDA

View Full Version : Solved: Lock Cells (Excel 2010)



joms
07-08-2013, 01:16 AM
hi guys,
I had protected some cells using VBA with this code below, it does protect the cells.
But when I click on the "Review" tab, and click on "Unprotect Sheet" it didn't prompt for a password.

Is there a way to do it, that when cells is protected via VBA and when the user click on the "Review" Tab to Unprotect the Sheet, a password confirmation will be prompted.

Any ideas is greatly appreciated.

Thanks in advance :)


ThisWorkbook.Worksheets("Sheet1").Cells.Locked = True

'Lock the cells
ThisWorkbook.Worksheets("Sheet1").Range("B1:B5535").Locked = True
ThisWorkbook.Worksheets("Sheet1").Protect Password:="123xxx"

GTO
07-08-2013, 05:55 PM
Hi there,

I just ran your three lines of code, from a Standard Module, in Excel 2010, and it faithfully asks for the password.

Mark

joms
07-09-2013, 12:31 AM
hmm.. it never asks on my side.. well i need to check my code..
i'm suspecting somewhere along the lines something is messing up.. Thanks..

snb
07-09-2013, 01:06 AM
Did you turn application.displayalerts off ?

JamesAl
07-09-2013, 02:07 AM
br {mso-data-placement:same-cell;}
Try these guidelines here http://www.ozgrid.com/VBA/protect-vba-code.htm.
This
article will guide you to protect your document. See whether it is what
you are looking for. When you set a password you must close and reopen
excel for the changes to take place.
Or use this method here http://www.techyv.com/questions/how-protect-my-microsoft-excel-spreadsheet.

joms
07-09-2013, 07:20 PM
hi all, thanks for the replies.
i have to set manually first the password on the worksheet.
then i used the same password via VBA.

and every time I click on the "Review" tab on the ribbon it will prompt for password already.

Thanks for the help :)