Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default VB protect sheet but allow certain options

Is there a way to use vb to not just protect a sheet but to choose specific
items in the "Protect Worksheet" dialogue box. (The, "Allow all users of this
worksheet to:" check boxes.)

This is 2003
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default VB protect sheet but allow certain options

Do you know about Format / Cells / Protection ?

"excel-chump" wrote:

Is there a way to use vb to not just protect a sheet but to choose specific
items in the "Protect Worksheet" dialogue box. (The, "Allow all users of this
worksheet to:" check boxes.)

This is 2003

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default VB protect sheet but allow certain options

Record a macro while you do it manually, to get the code. HTH Otto
"excel-chump" wrote in message
...
Is there a way to use vb to not just protect a sheet but to choose
specific
items in the "Protect Worksheet" dialogue box. (The, "Allow all users of
this
worksheet to:" check boxes.)

This is 2003



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default VB protect sheet but allow certain options

Record a macro when you choose the items you want chosen. You'll see the code.

excel-chump wrote:

Is there a way to use vb to not just protect a sheet but to choose specific
items in the "Protect Worksheet" dialogue box. (The, "Allow all users of this
worksheet to:" check boxes.)

This is 2003


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default VB protect sheet but allow certain options

Dave,
So obvious! Thanks. Also a another question: I have this in the worksheet
code.
'-----------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
'-----------------------------------------------------------------
ActiveSheet.Unprotect
Const WS_RANGE As String = "g3:f38" '<=== change to suit


On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Select Case .Value
Case "YES": .Interior.ColorIndex = 4 'green
Case "NO": .Interior.ColorIndex = 3 'red
Case "A1": .Interior.ColorIndex = 12 'dark yellow
Case "A2": .Interior.ColorIndex = 6 'yellow
Case 0: .Interior.ColorIndex = 19 'blank

End Select
End With
End If

ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowSorting:=True, AllowFiltering:=True
ws_exit:
Application.EnableEvents = True
End Sub

When I set the worksheet as shared it no longer works and I get an error
message:

"Run-time error '1004': Unprotect method of Worksheet class failed."

Are there any suggestions on how to work around that?



"Dave Peterson" wrote:

Record a macro when you choose the items you want chosen. You'll see the code.

excel-chump wrote:

Is there a way to use vb to not just protect a sheet but to choose specific
items in the "Protect Worksheet" dialogue box. (The, "Allow all users of this
worksheet to:" check boxes.)

This is 2003


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default VB protect sheet but allow certain options

You can't change the worksheet protection in a shared workbook.

You'll have to choose--either use protection or use sharing, but not both.

excel-chump wrote:

Dave,
So obvious! Thanks. Also a another question: I have this in the worksheet
code.
'-----------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
'-----------------------------------------------------------------
ActiveSheet.Unprotect
Const WS_RANGE As String = "g3:f38" '<=== change to suit

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Select Case .Value
Case "YES": .Interior.ColorIndex = 4 'green
Case "NO": .Interior.ColorIndex = 3 'red
Case "A1": .Interior.ColorIndex = 12 'dark yellow
Case "A2": .Interior.ColorIndex = 6 'yellow
Case 0: .Interior.ColorIndex = 19 'blank

End Select
End With
End If

ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowSorting:=True, AllowFiltering:=True
ws_exit:
Application.EnableEvents = True
End Sub

When I set the worksheet as shared it no longer works and I get an error
message:

"Run-time error '1004': Unprotect method of Worksheet class failed."

Are there any suggestions on how to work around that?

"Dave Peterson" wrote:

Record a macro when you choose the items you want chosen. You'll see the code.

excel-chump wrote:

Is there a way to use vb to not just protect a sheet but to choose specific
items in the "Protect Worksheet" dialogue box. (The, "Allow all users of this
worksheet to:" check boxes.)

This is 2003


--

Dave Peterson


--

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
Password Protect Excel Options Ed O'Brien Excel Discussion (Misc queries) 1 August 6th 09 05:29 PM
Protect selected settings in 'options' John Excel Worksheet Functions 4 June 15th 09 07:48 AM
what are my options to protect a sheet? Jason Excel Discussion (Misc queries) 1 March 5th 08 06:45 PM
Protect menu options dimmed Deborah[_2_] Excel Discussion (Misc queries) 1 August 1st 07 07:51 PM
Protect/Unprotect function options Floss Excel Programming 3 February 13th 05 08:07 PM


All times are GMT +1. The time now is 05:09 AM.

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

About Us

"It's about Microsoft Excel"