macro protection

A

albertmb

Hi everyone,

Is there a way to password protect macros especially those written to
command buttons. If someone fiddles with a macro, this can mess up the hole
work.

Thanks
Albert
 
T

Totti

you will need to protect the macros themselves so they cannot be
viewed without a password
(tools > vba project properties > protection > lock project with
password).
Then make the macros begin with a line that says :
if inputbox("Please enter the password")<>"password" then exit sub

replace <>"password" with <> whatever the password you want them to
type.
 
A

albertmb

Hi Totti, Thank you for your reply but I have to admit I am not so familiar
with Macros so if you do not mind I am putting a simple macro here and if
possible insert what you told me in it so as I can understand better. The
first part I managed, where I inserted the pasword. Thank You

Private Sub CommandButton2_Click()
Sheets("REPORT").Visible = True
Sheets("HOME").Select
ActiveWindow.SelectedSheets.Visible = False
End Sub

Albert
 
K

KC Rippstein hotmail com>

If you applied a password to your VBA project, then you're done.

Totti was taking it a step further and saying if you don't want someone to
use a macro unless they know a specific password (so they cannot click on a
button and use it unless they know that button's password), then you can
insert the line of code he told you about in the first line of your macro.

So if you have a button to run the macro you've shown us here but want to
limit the use of that button to just a few people, give them a special
password (different from your VBA project password, let's use "hi" for
example) and put this in your code.

Private Sub CommandButton2_Click()
If inputbox("Please enter the password") <> "hi" Then Exit Sub
Sheets("REPORT").Visible = True
Sheets("HOME").Select
ActiveWindow.SelectedSheets.Visible = False
End Sub
 
A

albertmb

Thank You KC for the explanation. I realy appreciate it. May I take this
opportunity to wish you all a most prosperous new year.

Albert
 

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