![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Feb 2002
Location: San Antonio, TX
Posts: 186
|
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 |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Apr 2002
Location: Vancouver BC , Canada
Posts: 6,259
|
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 |
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Feb 2002
Location: Huntington Beach, CA USA
Posts: 327
|
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 ] |
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Feb 2002
Location: San Antonio, TX
Posts: 186
|
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?
__________________
Russell |
|
|
|
|
|
#5 |
|
Board Regular
Join Date: Feb 2002
Location: Huntington Beach, CA USA
Posts: 327
|
In the TextBox1 "Properties" scrolldown to
PassWordChar and type * James |
|
|
|
|
|
#6 |
|
Board Regular
Join Date: Feb 2002
Location: San Antonio, TX
Posts: 186
|
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??
__________________
Russell |
|
|
|
|
|
#7 |
|
Board Regular
Join Date: Feb 2002
Location: Huntington Beach, CA USA
Posts: 327
|
Hi,
are you using the example code i posted? James |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|