VBA Code: When setting password, what does the true true true mean?

Badnames

Board Regular
Joined
Jun 12, 2007
Messages
211
In this line of code what do the different trues represent? I've been rewriting this portion of code for a lil bit now, and figure its time I learn what I'm doing.

Sub Protect()
Dim Password As String
Password = "protectresults"
Worksheets("Sheet1").Protect Password, True, True, True
End Sub
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Thanks Andrew!

Another question, I'm trying to setup the sheets so when protected users can:

Select Locked cells
Select Unlocked Cells
Format Cells
Format Columns
Format Rows


Do I just simply protect the sheet manually myself once before I run the macro to protect it?
 
Upvote 0
The full syntax for the Protect method is:

Protect(Password, DrawingObjects, Contents, Scenarios, UserInterfaceOnly, AllowFormattingCells, AllowFormattingColumns, AllowFormattingRows, AllowInsertingColumns, AllowInsertingRows, AllowInsertingHyperlinks, AllowDeletingColumns, AllowDeletingRows, AllowSorting, AllowFiltering, AllowUsingPivotTables)

The first 2 items in your list are contolled by the Worksheets's EnableSelection property. The possible settings are:

xlNoSelection prevents any selection on the sheet
xlUnlockedCells allows only those cells whose Locked property is False to be selected
xlNoRestrictions allows any cell to be selected.
 
Upvote 0

Forum statistics

Threads
1,224,559
Messages
6,179,517
Members
452,921
Latest member
BBQKING

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