![]() |
Protect Selected Sheets
I am trying to write some code to protect all of the selected sheets. I
kept getting an application error in the code below until I added the objSheet.Select line prior to the .Protect line. Why does it not work unless I select the sheet first? bAllOK = True For Each objSheet In ActiveWindow.SelectedSheets If Not bSheetIsProtected(objSheet) Then objSheet.Select objSheet.Protect Password:=strPW, Contents:=True Else strLocked = strLocked & Chr(10) & objSheet.Name bAllOK = False End If Next objSheet |
Protect Selected Sheets
Nevermind...I think I figured it out. You cannot protect sheets when
multiple sheets are selected (based on the fact that Tools | Protection | Protect Sheets is greyed out if more than one sheet is selected). The ..Select statement therefore works by ensuring only one sheet is selected. "M. Authement" wrote in message ... I am trying to write some code to protect all of the selected sheets. I kept getting an application error in the code below until I added the objSheet.Select line prior to the .Protect line. Why does it not work unless I select the sheet first? bAllOK = True For Each objSheet In ActiveWindow.SelectedSheets If Not bSheetIsProtected(objSheet) Then objSheet.Select objSheet.Protect Password:=strPW, Contents:=True Else strLocked = strLocked & Chr(10) & objSheet.Name bAllOK = False End If Next objSheet |
All times are GMT +1. The time now is 04:08 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com