VBA code to unprotect a protected sheet

jerronm

New Member
Joined
Jan 17, 2010
Messages
5
I need assistance developing vba code to unprotect a protected worksheet. Most tutorials concerning vba script and unprotecting sheets only refers to unprotecting an active sheet. I would like to have the vba script unprotect a specific sheet if possible. Please advise.

Ultimate Goal:
To prevent users of the worksheet from being able to input information into the raw data other than using the userform I've created.

The userform inputs information into the a sheet entitled "Details" and I'd like to have the "Details" sheet protected at all times. I would like the userform to be able to unprotect the "Details" sheet, input the data and protect the sheet when done.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Try

Code:
With Sheets("Details")
    .Unprotect Password:="abc"
'
'do stuff
'
    .Protect Password:="abc"
End With
 
Upvote 0
You can solve this problem when the workbook first opens. Just set the Details sheet to NOT allow user-changes, but to allow all changes to the sheet initiated by VBA (including your form).

Put this macro into the ThisWorkbook module. Save, then close/open the workbook. Then all your other macros will work even though the sheet is protected.
Rich (BB code):
Option Explicit

Private Sub Workbook_Open()
    Sheets("Details").Protect "password", UserInterfaceOnly:=True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,999
Messages
6,122,645
Members
449,093
Latest member
Ahmad123098

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