sorting a protected document


Posted by Sean Kiggans on March 15, 2001 8:34 AM

I have created a template and wish to protect the file. I have a button I would like to use to sort some data. Once I protect the sheet I can no longer sort. I receive a VB error:
Run-time error '1004'
Sort method of Range class failed
Is there anything I can do to sort a protected sheet? I do not know much about VB.

Posted by JAF on March 15, 2001 11:40 AM

Add the following lines at the beginning and end of your code:
ActiveSheet.Unprotect Password:="WHATEVERPASSWORD"
'Rest of Code
ActiveSheet.Protect Password:="WHATEVERPASSWORD"

That should sort your problem.

JAF



Posted by Dave Hawley on March 15, 2001 11:55 AM

Hi Sean

In addition to JAF's solution (which will work) you can set the protection via VBA that will still allow all code to run, but not allow a user to do things.

Sheets("Sheet1").Protect Password:="secret", Userinterfaceonly:=True


There are a few things that you should read in regards to this method though. While in the VBE place your insertion point in the word "Protect" and push F1


Dave

OzGrid Business Applications