Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Worksheet Functions / March 2006

Tip: Looking for answers? Try searching our database.

Unprotect worksheet via VBA

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike Echo - 17 Mar 2006 12:33 GMT
I tried to sort a sheet via VBA and kept getting an error until I
figured it was the protection stopping things. How can I turn off
protection, sort, then turn on protection again?

I looked in help and found ActiveWorkbook.Unprotect ("password") but it
doesn't work. Any pointers in the right direction much appreciated.

TIA,
R.
Chip Pearson - 18 Mar 2006 19:25 GMT
Try

ActiveSheet.Unprotect password:="whatever"
' do your sort
ActiveSheet.Protect password:="whatever"

Signature

Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

>I tried to sort a sheet via VBA and kept getting an error until
>I
[quoted text clipped - 9 lines]
> TIA,
> R.
Mike Echo - 19 Mar 2006 05:52 GMT
> ActiveSheet.Unprotect password:="whatever"
> ' do your sort
> ActiveSheet.Protect password:="whatever"

I found this code (on your website, no less :-)) and tried it but I
still get the same error message. If I unprotect the sheet the sort code
is fine. As soon as I protect the sheet things all go pear-shaped. This
has me baffled and I cannot imagine what may be causing it.

I recorded a macro to do the "unprotect then protect" thing and viewed
the code and even though I had entered a password, the macro didn't show
this. It simply showed "ActiveSheet Unprotect" etc.

I'll play more. It is probably something obviously stupid. That's
normally what happens with me. ;-)

Thanks for the reply, Chip.

*** Just had a thought. Could it be because I tend to put re-usable subs
in a module then "Call" them from the worksheet object as opposed to
having the same sub on different worksheets? My file is at work so I'll
have a look tomorrow.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.