View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Nigel[_8_] Nigel[_8_] is offline
external usenet poster
 
Posts: 172
Default Protect/Unprotect Sheet from Macro

Hi All
I have a worksheet that in large part has locked cells, the sheet is then
protected. This of course disables sort. What I am trying to do is
unprotect the sheet, do the sort and then protect the sheet. I have not as
yet added a password.

If I do the above manually from the UI, all is OK, but the macro that
follows fails on the sort method. The sheet is showing unprotected. Problem
in both xl97 and xl2002.

ActiveSheet.Unprotect

Selection.Sort Key1:=Range("B5"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True

TIA
Cheers
Nigel