Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Rob Rob is offline
external usenet poster
 
Posts: 234
Default Activesheet protection

Excel 2000
Hi,

I have a macro that I want to run only if the worksheet is protected, I've
tried code like: If ActiveSheet.Protection = False Then GoTo ResetMsg

ResteMgs:
MsgBox "Can't run macro!"
Exit Sub

The above doesn't work but I can't figure it out, any pointers most welcome.

Rob


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Activesheet protection

Hi Rob,

There are 3 protection properties. You can cater for all with

With ActiveSheet
If .ProtectContents = False Or _
.ProtectDrawingObjects = False Or _
.ProtectionMode = False Then
GoTo resetmsg
End If
End With

but you will probably only need ProtectContents.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Rob" wrote in message
...
Excel 2000
Hi,

I have a macro that I want to run only if the worksheet is protected, I've
tried code like: If ActiveSheet.Protection = False Then GoTo ResetMsg

ResteMgs:
MsgBox "Can't run macro!"
Exit Sub

The above doesn't work but I can't figure it out, any pointers most

welcome.

Rob




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default Activesheet protection

Try using:

If ActiveSheet.ProtectionMode = False Then GoTo ResetMsg

'Also, you need to spell "ResetMsg" consistently

Rob wrote:
Excel 2000
Hi,

I have a macro that I want to run only if the worksheet is protected, I've
tried code like: If ActiveSheet.Protection = False Then GoTo ResetMsg

ResteMgs:
MsgBox "Can't run macro!"
Exit Sub

The above doesn't work but I can't figure it out, any pointers most welcome.

Rob



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 103
Default Activesheet protection

TIP: assign a variable as worksheet then set the variable to the
sheet...that way Intellisense works and you'll get the enumerated values
too...

Sub Test()

Dim ws As Worksheet
Set ws = ActiveSheet
If ws.ProtectionMode = False Then
MsgBox "No Protection"
ElseIf ws.Protection.AllowDeletingRows = True Then
MsgBox "Delete rows off"
End If

End Sub

--
Patrick Molloy
Microsoft Excel MVP
---------------------------------
I Feel Great!
---------------------------------
"Rob" wrote in message
...
Excel 2000
Hi,

I have a macro that I want to run only if the worksheet is protected, I've
tried code like: If ActiveSheet.Protection = False Then GoTo ResetMsg

ResteMgs:
MsgBox "Can't run macro!"
Exit Sub

The above doesn't work but I can't figure it out, any pointers most
welcome.

Rob




  #5   Report Post  
Posted to microsoft.public.excel.programming
Rob Rob is offline
external usenet poster
 
Posts: 234
Default Activesheet protection

Thanks to you all, great solutions which I experiment with and go for the
most suited.

Thanks, Rob

"Patrick Molloy" wrote in message
...
TIP: assign a variable as worksheet then set the variable to the
sheet...that way Intellisense works and you'll get the enumerated values
too...

Sub Test()

Dim ws As Worksheet
Set ws = ActiveSheet
If ws.ProtectionMode = False Then
MsgBox "No Protection"
ElseIf ws.Protection.AllowDeletingRows = True Then
MsgBox "Delete rows off"
End If

End Sub

--
Patrick Molloy
Microsoft Excel MVP
---------------------------------
I Feel Great!
---------------------------------
"Rob" wrote in message
...
Excel 2000
Hi,

I have a macro that I want to run only if the worksheet is protected,

I've
tried code like: If ActiveSheet.Protection = False Then GoTo ResetMsg

ResteMgs:
MsgBox "Can't run macro!"
Exit Sub

The above doesn't work but I can't figure it out, any pointers most
welcome.

Rob








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Activesheet protection

I am not sure why anyone is suggesting ProtectionMode as the single property
to check. This is only true if the UserInterfaceOnly property of the
protect method has been used and this must be set using code. (at least
this is the way it works in xl2000 and xl97)

Bob Phillips is the closest, but there is one more property to check and I
would see the sense of the check being slightly different

With Worksheets("sheet1")
If .ProtectContents = False and _
.ProtectDrawingObjects = False and _
.ProtectScenarios = False and _
.ProtectionMode = False Then
GoTo resetmsg
End If
End With


exit sub
resetmsg :
msgbox "Sheet isn't protected"

I would suspect, however, that your macro might only be interested in the
Protectcontents property, so that might be all you need to check.


--
Regards,
Tom Ogilvy


"Rob" wrote in message
...
Thanks to you all, great solutions which I experiment with and go for the
most suited.

Thanks, Rob

"Patrick Molloy" wrote in message
...
TIP: assign a variable as worksheet then set the variable to the
sheet...that way Intellisense works and you'll get the enumerated values
too...

Sub Test()

Dim ws As Worksheet
Set ws = ActiveSheet
If ws.ProtectionMode = False Then
MsgBox "No Protection"
ElseIf ws.Protection.AllowDeletingRows = True Then
MsgBox "Delete rows off"
End If

End Sub

--
Patrick Molloy
Microsoft Excel MVP
---------------------------------
I Feel Great!
---------------------------------
"Rob" wrote in message
...
Excel 2000
Hi,

I have a macro that I want to run only if the worksheet is protected,

I've
tried code like: If ActiveSheet.Protection = False Then GoTo ResetMsg

ResteMgs:
MsgBox "Can't run macro!"
Exit Sub

The above doesn't work but I can't figure it out, any pointers most
welcome.

Rob








  #7   Report Post  
Posted to microsoft.public.excel.programming
Rob Rob is offline
external usenet poster
 
Posts: 234
Default Activesheet protection

Tom,

Thanks for the bit on ProtectionMode, it was the one element that seemed to
not work quite like the others. Also, AND is what I needed.

Rob
"Tom Ogilvy" wrote in message
...
I am not sure why anyone is suggesting ProtectionMode as the single

property
to check. This is only true if the UserInterfaceOnly property of the
protect method has been used and this must be set using code. (at least
this is the way it works in xl2000 and xl97)

Bob Phillips is the closest, but there is one more property to check and I
would see the sense of the check being slightly different

With Worksheets("sheet1")
If .ProtectContents = False and _
.ProtectDrawingObjects = False and _
.ProtectScenarios = False and _
.ProtectionMode = False Then
GoTo resetmsg
End If
End With


exit sub
resetmsg :
msgbox "Sheet isn't protected"

I would suspect, however, that your macro might only be interested in the
Protectcontents property, so that might be all you need to check.


--
Regards,
Tom Ogilvy


"Rob" wrote in message
...
Thanks to you all, great solutions which I experiment with and go for

the
most suited.

Thanks, Rob

"Patrick Molloy" wrote in message
...
TIP: assign a variable as worksheet then set the variable to the
sheet...that way Intellisense works and you'll get the enumerated

values
too...

Sub Test()

Dim ws As Worksheet
Set ws = ActiveSheet
If ws.ProtectionMode = False Then
MsgBox "No Protection"
ElseIf ws.Protection.AllowDeletingRows = True Then
MsgBox "Delete rows off"
End If

End Sub

--
Patrick Molloy
Microsoft Excel MVP
---------------------------------
I Feel Great!
---------------------------------
"Rob" wrote in message
...
Excel 2000
Hi,

I have a macro that I want to run only if the worksheet is

protected,
I've
tried code like: If ActiveSheet.Protection = False Then GoTo

ResetMsg

ResteMgs:
MsgBox "Can't run macro!"
Exit Sub

The above doesn't work but I can't figure it out, any pointers most
welcome.

Rob










  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Activesheet protection

I used xl2002:

I protected a worksheet with userinterfaceonly :=true. I unprotected the sheet
and .protectionmode still returned True.

I don't think I've ever worried about resetting that userinterfaceonly when I've
unprotected a sheet.

Option Explicit
Sub testme()
Dim wks As Worksheet
Set wks = ActiveSheet
With wks
.Protect userinterfaceonly:=True
MsgBox .ProtectionMode
.Unprotect
MsgBox .ProtectionMode
End With
End Sub

Unless the OP is very careful, it might not be useful to include in that in the
If statement.





Tom Ogilvy wrote:

I am not sure why anyone is suggesting ProtectionMode as the single property
to check. This is only true if the UserInterfaceOnly property of the
protect method has been used and this must be set using code. (at least
this is the way it works in xl2000 and xl97)

Bob Phillips is the closest, but there is one more property to check and I
would see the sense of the check being slightly different

With Worksheets("sheet1")
If .ProtectContents = False and _
.ProtectDrawingObjects = False and _
.ProtectScenarios = False and _
.ProtectionMode = False Then
GoTo resetmsg
End If
End With

exit sub
resetmsg :
msgbox "Sheet isn't protected"

I would suspect, however, that your macro might only be interested in the
Protectcontents property, so that might be all you need to check.

--
Regards,
Tom Ogilvy

"Rob" wrote in message
...
Thanks to you all, great solutions which I experiment with and go for the
most suited.

Thanks, Rob

"Patrick Molloy" wrote in message
...
TIP: assign a variable as worksheet then set the variable to the
sheet...that way Intellisense works and you'll get the enumerated values
too...

Sub Test()

Dim ws As Worksheet
Set ws = ActiveSheet
If ws.ProtectionMode = False Then
MsgBox "No Protection"
ElseIf ws.Protection.AllowDeletingRows = True Then
MsgBox "Delete rows off"
End If

End Sub

--
Patrick Molloy
Microsoft Excel MVP
---------------------------------
I Feel Great!
---------------------------------
"Rob" wrote in message
...
Excel 2000
Hi,

I have a macro that I want to run only if the worksheet is protected,

I've
tried code like: If ActiveSheet.Protection = False Then GoTo ResetMsg

ResteMgs:
MsgBox "Can't run macro!"
Exit Sub

The above doesn't work but I can't figure it out, any pointers most
welcome.

Rob







--

Dave Peterson

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Activesheet protection

It doesn't set itself. But, I agree that there is no need to check
..ProtectionMode.

--
Regards,
Tom Ogilvy


"Dave Peterson" wrote in message
...
I used xl2002:

I protected a worksheet with userinterfaceonly :=true. I unprotected the

sheet
and .protectionmode still returned True.

I don't think I've ever worried about resetting that userinterfaceonly

when I've
unprotected a sheet.

Option Explicit
Sub testme()
Dim wks As Worksheet
Set wks = ActiveSheet
With wks
.Protect userinterfaceonly:=True
MsgBox .ProtectionMode
.Unprotect
MsgBox .ProtectionMode
End With
End Sub

Unless the OP is very careful, it might not be useful to include in that

in the
If statement.





Tom Ogilvy wrote:

I am not sure why anyone is suggesting ProtectionMode as the single

property
to check. This is only true if the UserInterfaceOnly property of the
protect method has been used and this must be set using code. (at least
this is the way it works in xl2000 and xl97)

Bob Phillips is the closest, but there is one more property to check and

I
would see the sense of the check being slightly different

With Worksheets("sheet1")
If .ProtectContents = False and _
.ProtectDrawingObjects = False and _
.ProtectScenarios = False and _
.ProtectionMode = False Then
GoTo resetmsg
End If
End With

exit sub
resetmsg :
msgbox "Sheet isn't protected"

I would suspect, however, that your macro might only be interested in

the
Protectcontents property, so that might be all you need to check.

--
Regards,
Tom Ogilvy

"Rob" wrote in message
...
Thanks to you all, great solutions which I experiment with and go for

the
most suited.

Thanks, Rob

"Patrick Molloy" wrote in message
...
TIP: assign a variable as worksheet then set the variable to the
sheet...that way Intellisense works and you'll get the enumerated

values
too...

Sub Test()

Dim ws As Worksheet
Set ws = ActiveSheet
If ws.ProtectionMode = False Then
MsgBox "No Protection"
ElseIf ws.Protection.AllowDeletingRows = True Then
MsgBox "Delete rows off"
End If

End Sub

--
Patrick Molloy
Microsoft Excel MVP
---------------------------------
I Feel Great!
---------------------------------
"Rob" wrote in message
...
Excel 2000
Hi,

I have a macro that I want to run only if the worksheet is

protected,
I've
tried code like: If ActiveSheet.Protection = False Then GoTo

ResetMsg

ResteMgs:
MsgBox "Can't run macro!"
Exit Sub

The above doesn't work but I can't figure it out, any pointers

most
welcome.

Rob







--

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
name of the activesheet rasta Excel Programming 1 October 3rd 03 09:49 PM
ActiveSheet.Name? Andrew Stedman Excel Programming 5 July 30th 03 01:17 PM
ActiveSheet Graham[_3_] Excel Programming 0 July 30th 03 09:08 AM
ActiveSheet Ron de Bruin Excel Programming 0 July 29th 03 04:59 PM
ActiveSheet Graham[_3_] Excel Programming 0 July 29th 03 04:47 PM


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