Password on Macro Button

  • Thread starter Thread starter scuba
  • Start date Start date
S

scuba

Is it possible to have a macro assigned to a macro button that when the
button is selected it will ask for a password before the macro will run?
 
How about asking first thing in the macro:

Option Explicit
Sub Testme()
dim pwd as password
'more declarations

'before you do anything

pwd = inputbox(Prompt:="What's the password, Kenny?")

if pwd = "topSeCreT" then
'keep going
else
'nope, get out
exit sub
end if

'more code here

End sub

You may want to protect the project to make it a little more difficult for most
people to see the password in your code.

Select your project in the VBE
Tools|VBAProject|Protection tab
Give it a memorable password

Note that there are inexpensive project password breakers available. You won't
stop all, but you'll stop most.
 
A VERY simple password [password = HELLO] that is VERY unprotected would be...
'/========================================/
Sub MyMacroButton()
If SimplePassword(InputBox("Enter Password: ")) Then
'put code here
Else
Exit Sub
End If
End Sub
'/========================================/
Private Function SimplePassword(strAnswer As String) As Boolean
If UCase(strAnswer) = "HELLO" Then
SimplePassword = True
End If
End Function
'/========================================/
 

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

Back
Top