+ Reply to Thread
Results 1 to 2 of 2

VBA for form

  1. #1
    Forum Contributor
    Join Date
    05-04-2005
    Posts
    136

    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 here:

    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?

  2. #2
    Dave Peterson
    Guest

    Re: VBA for form

    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 here:
    >
    > 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1