Unprotect work sheet error

vbacoder12

New Member
Joined
Sep 4, 2024
Messages
12
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

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
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,221,444
Messages
6,159,914
Members
451,603
Latest member
SWahl

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