VBA for form

  • Thread starter Thread starter tkaplan
  • Start date Start date
T

tkaplan

I'm trying to create a macro that will protect and unprotect 10 sheet
in a workbook.

i have the code to protect etc. i'm having a problem here:

i created a form named frmPassword where i have a text field calle
My_Password.

what code would i use to open up that form and enter in a password
then when i click ok to assign whatever was in My_Password to
variable called My_Pass.

I tried My_Pass=frmPassword.My_Password but that doesnt work, probabl
because i never opened the form.

any help
 
I put this in a general module.

Option Explicit
Public myPass As String
Sub testme()
myPass = ""
UserForm1.Show
MsgBox myPass
End Sub

I created a userform (userform1) with a textbox and two buttons (ok and cancel).

I put this code behind the userform:
Option Explicit
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub CommandButton2_Click()
myPass = Me.my_Password.Text
Unload Me
End Sub

Running the sub TestMe shows the form and updates that myPass variable.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top