ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Protect/Unprotect Sheet from Macro (https://www.excelbanter.com/excel-programming/298336-protect-unprotect-sheet-macro.html)

Nigel[_8_]

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



Nigel[_8_]

Protect/Unprotect Sheet from Macro
 
Sorry everyone - stupid mistake - its nothing to do with protection the sort
method relies on a selection that I excluded.

Cheers
Nigel

"Nigel" wrote in message
...
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






All times are GMT +1. The time now is 08:32 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com