ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   PASSWORD PROMPTING CODE (https://www.excelbanter.com/excel-programming/278169-password-prompting-code.html)

Jay Dean

PASSWORD PROMPTING CODE
 
I have assigned a macro code to a command button in Excel. I need a
macro code to add to my original code that will prompt any user that
pushes the button to enter a password before the code assigned to the
button executes.
Any assistance will be appreciated.Thanks!

Jay Dean.

Paul B[_6_]

PASSWORD PROMPTING CODE
 
Jay, how about something like this

Sub PassWord_for_Macro()
'must lock VBA project so you can't see the password in it
Dim MyStr1 As String, MyStr2 As String
With ActiveSheet
MyStr2 = ("123") 'change to your password
MyStr1 = InputBox("Password Is Required To Run this Macro ")
If MyStr1 = MyStr2 Then
'*******your code here********
Else
MsgBox ("Password Does Not Match, Access Denied")
End If
End With
End Sub

--
Paul B
Always backup your data before trying something new
Using Excel 2000 & 97
Please post any response to the newsgroups so others can benefit from it
** remove news from my email address to reply by email **
"Jay Dean" wrote in message
om...
I have assigned a macro code to a command button in Excel. I need a
macro code to add to my original code that will prompt any user that
pushes the button to enter a password before the code assigned to the
button executes.
Any assistance will be appreciated.Thanks!

Jay Dean.




TroyW

PASSWORD PROMPTING CODE
 
Jay,

This code uses a simple InputBox to query the user for a password.

Troy


Sub RequestPassword()

Dim sReply As String

sReply = Application.InputBox( _
Prompt:="Please enter the password", _
Title:="Password Required", _
Type:=2)

If sReply = "thePassword" Then
'''Run the password protected code.
MsgBox sReply & " is the correct password"

Else
'''Do not run the password protected code.
MsgBox "Sorry, incorrect password"
End If

End Sub



"Jay Dean" wrote in message
om...
I have assigned a macro code to a command button in Excel. I need a
macro code to add to my original code that will prompt any user that
pushes the button to enter a password before the code assigned to the
button executes.
Any assistance will be appreciated.Thanks!

Jay Dean.




Jay Dean

PASSWORD PROMPTING CODE
 
Thank you very much. It worked beautifully !!

Jay Dean

"TroyW" wrote in message ...
Jay,

This code uses a simple InputBox to query the user for a password.

Troy


Sub RequestPassword()

Dim sReply As String

sReply = Application.InputBox( _
Prompt:="Please enter the password", _
Title:="Password Required", _
Type:=2)

If sReply = "thePassword" Then
'''Run the password protected code.
MsgBox sReply & " is the correct password"

Else
'''Do not run the password protected code.
MsgBox "Sorry, incorrect password"
End If

End Sub



"Jay Dean" wrote in message
om...
I have assigned a macro code to a command button in Excel. I need a
macro code to add to my original code that will prompt any user that
pushes the button to enter a password before the code assigned to the
button executes.
Any assistance will be appreciated.Thanks!

Jay Dean.



All times are GMT +1. The time now is 01:18 PM.

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