can any one help me with protect sheet

bhandari

Active Member
Joined
Oct 17, 2017
Messages
359
Code:
Private Sub Workbook_V1_Open()
Dim Wks As Worksheet

    For Each Wks In ThisWorkbook.Worksheets(1)
        Wks.Protect Password:="Engineer", UserInterFaceOnly:=True
    Next

End Sub
Code:
Private Sub protect_sheet()
    ActiveSheet.Protect Password:="Engineer", Drawing Objects:=True, Contents:=True, Scenarios:=True
End Sub
Code:
Private Sub unprotect_sheet()
    ActiveSheet.Unprotect Password:="Engineer"
End Sub

im trying to protect sheet getting error:438 object doesn't matched
can any one help me with this
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
This does not look correct to me:
Code:
    For Each Wks In ThisWorkbook.Worksheets(1)
Why would you be looping through a single sheet?

If you want to loop through all sheets, try:
Code:
    For Each Wks In ThisWorkbook.Worksheets
 
Last edited:
Upvote 0
Here is what I am using and it works just fine. However this will only lock and unlock cells that are selected to be locked.

[/CODE]
Code:
Private Sub Worksheet_Activate()
 ThisWorkbook.Worksheets("FULL INFORMATION").Unprotect Password:="PASSWORD"
'Unprotect

  ThisWorkbook.Worksheets("FULL INFORMATION").Protect Password:="PASSWORD"
'Protect
End Sub
Code:
Hope this helps or gives you an idea

Regards
Kevin


[QUOTE="bhandari, post: 4977057, member: 415070"][CODE]
Private Sub Workbook_V1_Open()
Dim Wks As Worksheet

    For Each Wks In ThisWorkbook.Worksheets(1)
        Wks.Protect Password:="Engineer", UserInterFaceOnly:=True
    Next

End Sub
Code:
Private Sub protect_sheet()
    ActiveSheet.Protect Password:="Engineer", Drawing Objects:=True, Contents:=True, Scenarios:=True
End Sub
Code:
Private Sub unprotect_sheet()
    ActiveSheet.Unprotect Password:="Engineer"
End Sub

im trying to protect sheet getting error:438 object doesn't matched
can any one help me with this[/QUOTE]
 
Upvote 0
its working if i remove worksheets(1)
Code:
For Each Wks In ThisWorkbook.Worksheets
there is a issue with using this code
i must run code separately by using command button because there are few objects which is generating sheets by "xlsheetveryhidden".
 
Upvote 0
Run Time error 1004
the cell or chart you are trying to change is on a protected sheet,To make a change,Unprotect the sheet,You might be Requested to enter a password.

Any one help me with this error
Code:
Private Sub Worksheet_Activate()
 ThisWorkbook.Worksheets("INPUT").Unprotect Password:="PASSWORD"
'Unprotect
ActiveSheet.Protect Password:="PASSWORD", DrawingObjects:=True, Contents:=True, Scenarios:=True
  ThisWorkbook.Worksheets("INPUT").Protect Password:="PASSWORD"
'Protect
End Sub
 
Last edited:
Upvote 0
The cell or the area that you are trying to make changes to is locked. Make sure to select that it is not locked and all should be good.

If you are trying to make changes to the entire sheet you will need to unlock have a wait and make changes then lock again.

Regards
Kevin



Run Time error 1004
the cell or chart you are trying to change is on a protected sheet,To make a change,Unprotect the sheet,You might be Requested to enter a password.

Any one help me with this error
Code:
Private Sub Worksheet_Activate()
 ThisWorkbook.Worksheets("INPUT").Unprotect Password:="PASSWORD"
'Unprotect
ActiveSheet.Protect Password:="PASSWORD", DrawingObjects:=True, Contents:=True, Scenarios:=True
  ThisWorkbook.Worksheets("INPUT").Protect Password:="PASSWORD"
'Protect
End Sub
 
Upvote 0
i got the solution
can you please add this to my code ,Except this columns "AE:AT,X" i want to protect whole sheet
please find the below code
Code:
Sheets("INPUT").Protect Password:="Engineer", DrawingObjects:=True, Contents:=True, Scenarios:=True
its protecting whole sheet, except 3 columns i want to protect sheet
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

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