Password protect a worksheet using VBA

Broccoli

New Member
Joined
Mar 22, 2009
Messages
6
Hi there

Is there a way to password protect a worksheet using VBA?

I'm trying to password protect a sheet with the password "coffee".

However when I record and run a a macro to do this, the sheet is protected but without a password. Ie the VBA code does not state that the password must be coffee, it just protects the sheet without a password.

Below is the code the code generated by the macro:

ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Just add a named argument, Password:=

ActiveSheet.Protect Password:= "coffee", DrawingObjects:=True, Contents:=True, Scenarios:=True
 
Upvote 0

Forum statistics

Threads
1,215,692
Messages
6,126,228
Members
449,303
Latest member
grantrob

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