Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default unprotect sheet failure

I'm using the code below to switch between a development enviroment, where I
can view private data and change anything I want to on a sheet, and a user
environment where private data is hidden and the user interface is
protected.

It works, EXCEPT for whatever happens to be the active sheet when I invoke
the macro.

Thanks In Advance!
Eric

Public Sub ProtectAllSheets(protectionLevel As ProtectionOptions)
On Error GoTo ProtectAllSheets_Error

Dim wks As Worksheet
For Each wks In ActiveWorkbook.Sheets
Select Case protectionLevel
Case Protect
Call wks.Protect(UserInterfaceOnly:=False, Password:=pWord)
Case Unprotect
Call wks.Unprotect(pWord)
End Select
Next wks

On Error GoTo 0
Exit Sub

ProtectAllSheets_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
ProtectAllSheets of Module MSecurity"

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default unprotect sheet failure

Have you tried quotation marks around the select parameters?
Case "Protect"
Call wks.Protect(UserInterfaceOnly:=False,
Password:=Pword)Case "Unprotect"
HTH
"Eric" wrote:

I'm using the code below to switch between a development enviroment, where I
can view private data and change anything I want to on a sheet, and a user
environment where private data is hidden and the user interface is
protected.

It works, EXCEPT for whatever happens to be the active sheet when I invoke
the macro.

Thanks In Advance!
Eric

Public Sub ProtectAllSheets(protectionLevel As ProtectionOptions)
On Error GoTo ProtectAllSheets_Error

Dim wks As Worksheet
For Each wks In ActiveWorkbook.Sheets
Select Case protectionLevel
Case Protect
Call wks.Protect(UserInterfaceOnly:=False, Password:=pWord)
Case Unprotect
Call wks.Unprotect(pWord)
End Select
Next wks

On Error GoTo 0
Exit Sub

ProtectAllSheets_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
ProtectAllSheets of Module MSecurity"

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default unprotect sheet failure

No, those case breaks are just normal enums. And the routine does work for
every sheet in the workbook except for the active sheet.

Thanks anyway.

"Gleam" wrote in message
...
Have you tried quotation marks around the select parameters?
Case "Protect"
Call wks.Protect(UserInterfaceOnly:=False,
Password:=Pword)Case "Unprotect"
HTH
"Eric" wrote:

I'm using the code below to switch between a development enviroment,
where I
can view private data and change anything I want to on a sheet, and a
user
environment where private data is hidden and the user interface is
protected.

It works, EXCEPT for whatever happens to be the active sheet when I
invoke
the macro.

Thanks In Advance!
Eric

Public Sub ProtectAllSheets(protectionLevel As ProtectionOptions)
On Error GoTo ProtectAllSheets_Error

Dim wks As Worksheet
For Each wks In ActiveWorkbook.Sheets
Select Case protectionLevel
Case Protect
Call wks.Protect(UserInterfaceOnly:=False,
Password:=pWord)
Case Unprotect
Call wks.Unprotect(pWord)
End Select
Next wks

On Error GoTo 0
Exit Sub

ProtectAllSheets_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in
procedure
ProtectAllSheets of Module MSecurity"

End Sub





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default unprotect sheet failure

Maybe the password isn't the same for the activesheet???

I don't think it should matter, but that's kind of a weird use of the Call
statement. I'd use:

For Each wks In ActiveWorkbook.Sheets
Select Case protectionLevel
Case Protect
wks.Protect UserInterfaceOnly:=False, Password:=pWord
Case Unprotect
wks.Unprotect password:=pWord 'I like keywords!
End Select
Next wks


And I'm not sure I'd use Protect and Unprotect as constants/enums either. They
may not confuse excel, but they would me.


Eric wrote:

I'm using the code below to switch between a development enviroment, where I
can view private data and change anything I want to on a sheet, and a user
environment where private data is hidden and the user interface is
protected.

It works, EXCEPT for whatever happens to be the active sheet when I invoke
the macro.

Thanks In Advance!
Eric

Public Sub ProtectAllSheets(protectionLevel As ProtectionOptions)
On Error GoTo ProtectAllSheets_Error

Dim wks As Worksheet
For Each wks In ActiveWorkbook.Sheets
Select Case protectionLevel
Case Protect
Call wks.Protect(UserInterfaceOnly:=False, Password:=pWord)
Case Unprotect
Call wks.Unprotect(pWord)
End Select
Next wks

On Error GoTo 0
Exit Sub

ProtectAllSheets_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
ProtectAllSheets of Module MSecurity"

End Sub


--

Dave Peterson
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
vlookup failure & ctrl-f failure? joemeshuggah Excel Discussion (Misc queries) 4 December 22nd 08 07:22 PM
Ctrl+Home failure when sheet protected Drew[_2_] Excel Discussion (Misc queries) 1 March 19th 08 06:18 AM
Copying objects to new sheet failure Steven Excel Discussion (Misc queries) 0 July 25th 07 02:50 PM
Chart versus Work Sheet Code Failure Nigel Excel Programming 2 April 18th 05 05:16 PM
unprotect sheet in code and make sheet visible peach255 Excel Programming 1 August 1st 03 03:28 AM


All times are GMT +1. The time now is 11:52 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"