+ Reply to Thread
Results 1 to 3 of 3

Need to protect with Password

  1. #1
    f_amshan
    Guest

    Need to protect with Password

    Hi all,

    I have command button which macro has been applied to it. i would like to
    protect this command button with passowrd. so, when any one click on this
    command button,it should ask for a password.

    Regards,
    Faisal M.

  2. #2
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243
    Hi Faisal,

    Try adding the following to the code for your command button:

    Private Sub CommandButton1_Click()
    Dim InitialFilterValue As String
    InitialFilterValue = InputBox("Please enter the password.", "PASSWORD REQUIRED")
    'To end sub if "cancel" was pressed or passowrd is wrong, sourced from _
    http://www.excelforum.com/showthread...vbcancel+input & http://vb.mvps.org/tips/varptr.asp
    If StrPtr(InitialFilterValue) = 0 Then
    Exit Sub
    Else
    If InitialFilterValue = "secret" Then
    Else
    Exit Sub
    End If
    End If
    'enter your code here
    End Sub

    This is just a starting point as there are ways of making it loop until the correct password is entered or only allowing 3 tries etc.

    NB: To prevent anyone opening the VB Editor to identify the password as "secret" you will need to lock the VB Project. To do this right click on a module/sheet code in the VBE & select VBA Project Properties - Lock for Viewing.

    hth
    Rob Brockett
    NZ
    Always learning & the best way to learn is to experience...

  3. #3
    Dave Peterson
    Guest

    Re: Need to protect with Password

    You could add something like this to the top of the routine.



    dim myPWD as string
    dim resp as string

    myPWD = "topSeCreT"
    resp = inputbox(Prompt:="What's the password, Kenny?")

    if resp <> mypwd then
    msgbox "Not authorized to use this button!
    exit sub
    end if


    f_amshan wrote:
    >
    > Hi all,
    >
    > I have command button which macro has been applied to it. i would like to
    > protect this command button with passowrd. so, when any one click on this
    > command button,it should ask for a password.
    >
    > Regards,
    > Faisal M.


    --

    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