![]() |
![]() |
|
|||||||
| 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
Posts: 133
|
I am a total novice concerning UserForms. I have managed to design the form it has 1 TextBox and 2 buttons on it. I want users to input a password into the TextBox and then press 1 of the buttons marked "OK" to then opperate a macro or if they press the other button marked "Cancel" to make the UserForm disappear. Help !
|
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Mar 2002
Location: Arkansas
Posts: 358
|
Im Just learning myself, This came out of one of my lesson books, Hope it helps
Private Sub cmdValid_Click() 'This procedure checks the input password Dim Response As Integer If txtPassword.Text = txtPassword.Tag Then 'If correct, display message box MsgBox "You've passed security!", vbOKOnly + vbExclamation, "Access Granted" Else 'If incorrect, give option to try again Response = MsgBox("Incorrect password", vbRetryCancel + vbCritical, "Access Denied") If Response = vbRetry Then txtPassword.SelStart = 0 txtPassword.SelLength = Len(txtPassword.Text) Else End End If End If txtPassword.SetFocus End Sub |
|
|
|
|
|
#3 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
|
Double click on the "OK" button and this will throw up code that looks like this:
Between these two lines put in the name of your macro. e.g. if I wanted to run a macro called "MyMacro" my code would look like this:
Go back to your userform view and double click on the "Cancel" button, put this code in:
HTH |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|