Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Strange worksheet protection behavior

Using Excel 2007 Beta, and I use the code below during the running of my
macro. The strange thing is that before I exit the workbook I cannot select
locked cells (this is as it should be, only want to select unlocked cells)
but when the workbook is reopened, worksheet protection is still turned on,
but I can now select locked cells.



Sub Protect_All_Sheets()
'
' Protect_All_Sheets
'

'

With ThisWorkbook
.Worksheets("June - August").Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells
.Worksheets("September - November").Protect DrawingObjects:=True,
Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells
.Worksheets("December - February").Protect DrawingObjects:=True,
Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells
.Worksheets("March - May").Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells

End With

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Strange worksheet protection behavior

Hi Patrick,

Try setting the protection in the workbook open event.


---
Regards,
Norman



"Patrick Simonds" wrote in message
...
Using Excel 2007 Beta, and I use the code below during the running of my
macro. The strange thing is that before I exit the workbook I cannot
select locked cells (this is as it should be, only want to select unlocked
cells) but when the workbook is reopened, worksheet protection is still
turned on, but I can now select locked cells.



Sub Protect_All_Sheets()
'
' Protect_All_Sheets
'

'

With ThisWorkbook
.Worksheets("June - August").Protect DrawingObjects:=True,
Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells
.Worksheets("September - November").Protect DrawingObjects:=True,
Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells
.Worksheets("December - February").Protect DrawingObjects:=True,
Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells
.Worksheets("March - May").Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells

End With

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Strange worksheet protection behavior

Okay I placed the code under workbook open, but, it only protects the active
sheet when you open the workbook. I had hoped it would work on all of the
worksheets.



Private Sub Workbook_Open()

With ThisWorkbook
.Worksheets("June - August").Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells
.Worksheets("September - November").Protect DrawingObjects:=True,
Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells
.Worksheets("December - February").Protect DrawingObjects:=True,
Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells
.Worksheets("March - May").Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells

End With

End Sub


"Norman Jones" wrote in message
...
Hi Patrick,

Try setting the protection in the workbook open event.


---
Regards,
Norman



"Patrick Simonds" wrote in message
...
Using Excel 2007 Beta, and I use the code below during the running of my
macro. The strange thing is that before I exit the workbook I cannot
select locked cells (this is as it should be, only want to select
unlocked cells) but when the workbook is reopened, worksheet protection
is still turned on, but I can now select locked cells.



Sub Protect_All_Sheets()
'
' Protect_All_Sheets
'

'

With ThisWorkbook
.Worksheets("June - August").Protect DrawingObjects:=True,
Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells
.Worksheets("September - November").Protect DrawingObjects:=True,
Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells
.Worksheets("December - February").Protect DrawingObjects:=True,
Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells
.Worksheets("March - May").Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells

End With

End Sub





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Strange worksheet protection behavior

Hi Patrick,

Okay I placed the code under workbook open, but, it only protects the
active sheet when you open the workbook. I had hoped it would work on all
of the worksheets.


Your problem is that:

ActiveSheet.EnableSelection = xlUnlockedCells


always refers to the active sheet.

Try instead:

'=============
Private Sub Workbook_Open()
Dim SH As Worksheet
Const PWORD As String = "ABC" '<<=== CHANGE

For Each SH In Me.Worksheets
With SH
.Protect Password:=PWORD, _
DrawingObjects:=True, _
Contents:=True, _
Scenarios:=True
.EnableSelection = xlUnlockedCells
End With
Next SH

End Sub
'<<=============

---
Regards,
Norman



"Patrick Simonds" wrote in message
...
Okay I placed the code under workbook open, but, it only protects the
active sheet when you open the workbook. I had hoped it would work on all
of the worksheets.



Private Sub Workbook_Open()

With ThisWorkbook
.Worksheets("June - August").Protect DrawingObjects:=True,
Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells
.Worksheets("September - November").Protect DrawingObjects:=True,
Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells
.Worksheets("December - February").Protect DrawingObjects:=True,
Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells
.Worksheets("March - May").Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells

End With

End Sub


"Norman Jones" wrote in message
...
Hi Patrick,

Try setting the protection in the workbook open event.


---
Regards,
Norman



"Patrick Simonds" wrote in message
...
Using Excel 2007 Beta, and I use the code below during the running of my
macro. The strange thing is that before I exit the workbook I cannot
select locked cells (this is as it should be, only want to select
unlocked cells) but when the workbook is reopened, worksheet protection
is still turned on, but I can now select locked cells.



Sub Protect_All_Sheets()
'
' Protect_All_Sheets
'

'

With ThisWorkbook
.Worksheets("June - August").Protect DrawingObjects:=True,
Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells
.Worksheets("September - November").Protect DrawingObjects:=True,
Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells
.Worksheets("December - February").Protect DrawingObjects:=True,
Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells
.Worksheets("March - May").Protect DrawingObjects:=True,
Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells

End With

End Sub







  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Strange worksheet protection behavior

Hi Patrick,

Replace the suggested code with:

'=============
Private Sub Workbook_Open()
Dim SH As Worksheet
Const PWORD As String = "ABC" '<<=== CHANGE

For Each SH In Me.Worksheets
With SH
.Unprotect password:=PWORD
.EnableSelection = xlUnlockedCells
.Protect password:=PWORD, _
DrawingObjects:=True, _
Contents:=True, _
Scenarios:=True
End With
Next SH

End Sub
'<<=============

---
Regards,
Norman




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Strange worksheet protection behavior

Thanks for your time and code

"Norman Jones" wrote in message
...
Hi Patrick,

Replace the suggested code with:

'=============
Private Sub Workbook_Open()
Dim SH As Worksheet
Const PWORD As String = "ABC" '<<=== CHANGE

For Each SH In Me.Worksheets
With SH
.Unprotect password:=PWORD
.EnableSelection = xlUnlockedCells
.Protect password:=PWORD, _
DrawingObjects:=True, _
Contents:=True, _
Scenarios:=True
End With
Next SH

End Sub
'<<=============

---
Regards,
Norman



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange behavior Ritchie Excel Discussion (Misc queries) 2 September 26th 06 02:21 AM
Strange TAB behavior m davidson Excel Programming 4 May 28th 06 06:09 PM
Strange behavior DeRussie Setting up and Configuration of Excel 4 November 26th 05 05:41 PM
Strange behavior. Wiley Coyote Excel Discussion (Misc queries) 7 October 18th 05 04:35 PM
Strange Worksheet Protection [email protected] Excel Programming 2 July 8th 05 08:14 AM


All times are GMT +1. The time now is 11:12 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"