Protect UserInterfaceOnly:=True

wschiro

New Member
Joined
Aug 29, 2004
Messages
9
Hi

I would like to protect a worksheet and at the same time be able to do calculation, cut and paste functions via macros.

This is the code I am using

Private Sub Workbook_Open()
Sheets("Calculations").Protect UserInterfaceOnly:=True
end sub

This code protects the sheet but all I have to do is tools>protection> unprotect sheet from the menu and this unprotect the sheet. I do not need to supply a password.

Is there a way to use a password with the

sheet1.Protect UserInterfaceOnly:=True

Charles
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Sheet1.Protect Password:="Password", UserInterfaceOnly:=True
 
Upvote 0
Thanks DRJ,

I was missing the comma so I was getting a syntax error.
Then I tried using two line of code and that resulted in the original post scenario.


Sheets("Calculations").Protect Password:="Password"
Sheets("Calculations").Protect UserInterfaceOnly:=True

Thanks for the fast responds. To further my understanding why doesn’t the above code work? Well, works as far as protects worksheet but no password


Charles
 
Upvote 0
That code works for me.

You don't need to protect the sheet with a password just to use the user interface option. If the sheet already is protected with a password just use the userinterfaceonly line. For example you can do this when the workbook opens.

Code:
Private Sub Workbook_Open()

Dim Sh          As Worksheet

    For Each Sh In Worksheets
        Sh.Protect UserInterFaceOnly:=True
    Next
    
End Sub

Then any macro can make changes and you don't have to worry about unprotecting the sheets.
 
Upvote 0

Forum statistics

Threads
1,215,236
Messages
6,123,798
Members
449,127
Latest member
Cyko

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