ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Password on Macro Button (https://www.excelbanter.com/excel-discussion-misc-queries/196537-password-macro-button.html)

scuba

Password on Macro Button
 
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?

Dave Peterson

Password on Macro Button
 
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.




scuba wrote:

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?


--

Dave Peterson

Gary Brown[_4_]

Password on Macro Button
 
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
'/========================================/
--
Hope this helps.
Thanks in advance for your feedback.
Gary Brown


"scuba" wrote:

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?


scuba

Password on Macro Button
 
Thank you to both of you for your help. I got it to work.


All times are GMT +1. The time now is 11:52 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com