password from userform

ermccarthy

Board Regular
Joined
Feb 15, 2002
Messages
224
I have a macro, that I want to run if the input in the userform is correct (password).

The below macro is a simple one that I do not want to execute unless the password inputted is correct....my problem is...I do not know how to do this, I wrote the macro, and created the userform and it seems to be working ok but how do I "capture the input" and run a comparison to what the password will be in the programming....any ideas.

UserForm1.Show
Range("A3:H53").Select
Range("B3").Activate
Selection.Locked = True
Range("E6").Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="wsr"
Range("F7").Select
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
I will assume your userform has a textbox called textbox1.
in your code state:
dim passwd as string
passwd = trim(form1.textbox1.text)
in the following line:
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="wsr"

replace the constant "wsr" with the variable you've create ie passwd
With
 
Upvote 0
Hi,

Try something like this:

Private Sub CommandButton_Click()
If TextBox1 = "wsr" Then
'your code
Else
If TextBox1<> "wsr" Then
MsgBox"Password Failed!", vbOkOnly + _vbCritical
End If
End If
End Sub

James


_________________
This message was edited by James on 2002-05-06 12:21
 
Upvote 0
This worked!!!!!!!!!

But one more question.....When I bring that userfrom back up, my password is still there, how can I make it clear out each time the userform is opened?
 
Upvote 0
I do have it masked with that property, but the problem is the next time I pull up that userform, the input is still there, masked but still there.

I would like to have that textbox cleared each time the userform is opened.

Any ideas??
 
Upvote 0

Forum statistics

Threads
1,213,491
Messages
6,113,963
Members
448,536
Latest member
CantExcel123

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top