VBA to check protection details of an excel sheet

QualEng

New Member
Joined
Aug 15, 2018
Messages
13
I have an excel 2010 workbook which has a number of sheets whichhave two stages of protection
1 Fully locked for viewing only – Viewing Mode
2 Some unprotected areas for editing data - Edit Mode,selected by password protected button.
I have a button for adding rows whilst in Edit Mode I wantto be able to tell the user that they are trying to insert a row into a ViewingMode sheet and should select the Edit mode.
I have code (Shown below) which can check if the sheet isprotected or not protected, which works, but both the available modes areprotected versions of the sheet. How can I get VBA code to tell if fully orpartially protected?
I tried changing the ProtectContents command to EnableSelection= xlUnlockedCells which would show difference between the two modes, but thatdidn’t work.
Any help would be much appreciated

Sub InsertRowProtectionCheck()
If ActiveSheet.ProtectContents = TrueThen
MsgBox"Please choose Edit mode to carry out this function"
Exit Sub
Else
End If
MSG1 =MsgBox("Are you sure you have selected a cell in a blank row? (not in row1)", vbYesNo, "Correct Selection?")
If MSG1 = vbNoThen
Else
CallInsertRowAbove
End If
End Sub
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
If in view mode, user can not select cells but he can in edit mode, then maybe

Code:
If (ActiveSheet.ProtectContents = True And ActiveSheet.EnableSelection = xlNoSelection) Then
    MsgBox "Please choose Edit mode to carry out this function"
End If
 
Upvote 0

Forum statistics

Threads
1,215,391
Messages
6,124,674
Members
449,179
Latest member
fcarfagna

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