Using a Worksheet_BeforeDoubleClick

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Using a Worksheet_BeforeDoubleClick

Post by ABabeNChrist »

I’m using a Worksheet_BeforeDoubleClick like so

Code: Select all

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

    If Not Intersect(Target, Range("C1")) Is Nothing Then
   'Code here
  End If
End Sub
Can I add something that will do, If sheet is protected Then Exit sub, or something like that…
so as not to run code if sheet is protected.

User avatar
mbarron
2StarLounger
Posts: 112
Joined: 25 Jan 2010, 20:19

Re: Using a Worksheet_BeforeDoubleClick

Post by mbarron »

Something like this at the begining should do it:

Code: Select all

If ActiveSheet.ProtectContents = True Then Cancel = True

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Using a Worksheet_BeforeDoubleClick

Post by ABabeNChrist »

mbarron wrote:Something like this at the begining should do it:

Code: Select all

If ActiveSheet.ProtectContents = True Then Cancel = True
Thank you mbarron
I was at first trying

Code: Select all

If ActiveSheet.Protect = True then
but of course that was incorrect.
I then realized i needed to add Contents as you have
so now i have

Code: Select all

        If ActiveSheet.ProtectContents = True Then
            MsgBox ("Sheet is protected")
            Exit Sub
        End If