VBA Worksheet Protection = T/F

Nickalas

New Member
Joined
Aug 19, 2010
Messages
17
Hi All,

I'm trying to learn VBA but i need a little help :confused:

I'm trying to check whether a worksheet is protected and return a value of "True" or "False" in a cell on a different worksheet. I also need the result to be always live/up to date.

This is what I have so far. Any help would be greatly appreciated.

Code:
Private Sub Worksheet_CheckProtect()
 
    If TargetSheet.ProtectContents = True Then
    
        Worksheets("Dashboard").Range("B4") = "True"
    Else
        Worksheets("Dashboard").Range("B4") = "False"
    End If
 
End Sub

Thank you
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Should it be?

Rich (BB code):
If ActiveSheet.ProtectContents = True Then
 
Upvote 0
Aha...now I get a result, thank you :)

One final question....I have it working using Worksheet_Activate(). What's the best way to ensure the result is always up to date? I was thinking maybe every time a different worksheet is selected or alike?

Thanks
 
Upvote 0
Try in the ThisWorkbook module

Code:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Sh.Range("B4").Value = Sh.ProtectContents
End Sub
 
Upvote 0

Forum statistics

Threads
1,203,125
Messages
6,053,648
Members
444,676
Latest member
locapoca

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top