Password for cell protection within VBA

M

Mike

I have a VBA routine where the user inputs several items & then clicks
a "calc" button to get an answer that is then entered into a certain
cell by the VBA code. I want to enable protection (w/password) so
that only the user input cells can be selected/edited. I added code
for the calc button to unprotect the sheet, enter the answer into the
cell, and then turn protection back on. My problem is that upon
execution of the line that unprotects the sheet, a dialog box pops up
for the user to enter the "protection" password, which they of course
do not have.

How can I use VBA code to provide the password?
 
M

Mike H

Mike,

hard code the password

ActiveSheet.Unprotect Password:="MyPass"
'do things
ActiveSheet.Protect Password:="MyPass"

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top