#1   Report Post  
tkaplan
 
Posts: n/a
Default VBA for form


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

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

i created a form named frmPassword where i have a text field called
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 a
variable called My_Pass.

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

any help?


--
tkaplan
------------------------------------------------------------------------
tkaplan's Profile: http://www.excelforum.com/member.php...o&userid=22987
View this thread: http://www.excelforum.com/showthread...hreadid=376355

  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default

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.



tkaplan wrote:

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

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

i created a form named frmPassword where i have a text field called
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 a
variable called My_Pass.

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

any help?

--
tkaplan
------------------------------------------------------------------------
tkaplan's Profile: http://www.excelforum.com/member.php...o&userid=22987
View this thread: http://www.excelforum.com/showthread...hreadid=376355


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 09:08 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"