Unprotect work sheet error

vbacoder12

New Member
Joined
Sep 4, 2024
Messages
20
Office Version
  1. Prefer Not To Say
Platform
  1. Windows
Hi.
I wrote the vba below to keep a workbook open until a certain date then lock it. When I try to unprotect I get "this password you supplied is not correct. Verify that the caps locks is off and be sure to use the correct capitalization.

Private Sub worksheet()
Activesheet.unprotect password ="dog98"
If Date > dateserial (2024,9,15) then
Range ("H:N").locked=TRUE
Range("A:G").locked=TRUE
Activesheet.Protect Password="dog98"
ThisWorkbook.Save
End If
End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
That is not a valid event procedure:
VBA Code:
Private Sub worksheet()

How/when, exactly are you trying to run that code?
 
Upvote 0
And as I mentioned in our other thread, those line should look like:
VBA Code:
Activesheet.Unprotect Password:="dog98"
and
VBA Code:
Activesheet.Protect Password:="dog98"
 
Upvote 0
And as I mentioned in our other thread, those line should look like:
VBA Code:
Activesheet.Unprotect Password:="dog98"
and
VBA Code:
Activesheet.Protect Password:="dog98"
Seems like it this code when the : is only on the protected password line. Once I added that it runs as intended.
 
Upvote 0

Forum statistics

Threads
1,223,891
Messages
6,175,229
Members
452,621
Latest member
Laura_PinksBTHFT

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