+ Reply to Thread
Results 1 to 4 of 4

Password Protecting a particular Sub

  1. #1
    Registered User
    Join Date
    04-21-2006
    Posts
    61

    Password Protecting a particular Sub

    Hi All,
    I'm looking to put in some sort of protection that will require a password to run a particluar sub in an excel file. The sub will be attached to a button...

    I had thought that I should pop up an input box (somehow!) and then compare the input from the user to a defined constant in the code... is this the best way, and if so, how do I write the input box code?

    Here's the button code as it stands... it's nothing special!

    Private Sub CommandButton4_Click()
    Overduepdp
    ProtectSheet
    End Sub

    Thanks all.

    Gareth

  2. #2
    Registered User
    Join Date
    04-21-2006
    Posts
    61

    I've got this so far...!

    Dim password As String
    Private Sub CommandButton4_Click()
    password = "clearannual"
    Set passwordinput = Application.InputBox(prompt:="Input Password to Clear Annual Dates", Type:=2)
    If passwordinput = password Then
    Overduepdp
    ProtectSheet
    Else
    response = MsgBox("Incorrect Password Supplied. Please try again", vbOKOnly, "Clear Annual dates Password")
    End If
    End Sub

    Obviously it's not working yet...

  3. #3
    Harald Staff
    Guest

    Re: Password Protecting a particular Sub

    In its simplest form

    Private Sub CommandButton4_Click()
    If InputBox("Password please:") <> "Top Secret" Then Exit Sub
    Overduepdp
    ProtectSheet
    End Sub

    HTH. Best wishes Harald

    "pianoman" <[email protected]> skrev i
    melding news:[email protected]...
    >
    > Hi All,
    > I'm looking to put in some sort of protection that will require a
    > password to run a particluar sub in an excel file. The sub will be
    > attached to a button...
    >
    > I had thought that I should pop up an input box (somehow!) and then
    > compare the input from the user to a defined constant in the code... is
    > this the best way, and if so, how do I write the input box code?
    >
    > Here's the button code as it stands... it's nothing special!
    >
    > Private Sub CommandButton4_Click()
    > Overduepdp
    > ProtectSheet
    > End Sub
    >
    > Thanks all.
    >
    > Gareth
    >
    >
    > --
    > pianoman
    > ------------------------------------------------------------------------
    > pianoman's Profile:
    > http://www.excelforum.com/member.php...o&userid=33712
    > View this thread: http://www.excelforum.com/showthread...hreadid=544564
    >




  4. #4
    Registered User
    Join Date
    04-21-2006
    Posts
    61

    Works

    Magic Harald,
    Works just fine.

    Many thanks,

    Gareth

    Quote Originally Posted by Harald Staff
    In its simplest form

    Private Sub CommandButton4_Click()
    If InputBox("Password please:") <> "Top Secret" Then Exit Sub
    Overduepdp
    ProtectSheet
    End Sub

    HTH. Best wishes Harald

    "pianoman" <[email protected]> skrev i
    melding news:[email protected]...
    >
    > Hi All,
    > I'm looking to put in some sort of protection that will require a
    > password to run a particluar sub in an excel file. The sub will be
    > attached to a button...
    >
    > I had thought that I should pop up an input box (somehow!) and then
    > compare the input from the user to a defined constant in the code... is
    > this the best way, and if so, how do I write the input box code?
    >
    > Here's the button code as it stands... it's nothing special!
    >
    > Private Sub CommandButton4_Click()
    > Overduepdp
    > ProtectSheet
    > End Sub
    >
    > Thanks all.
    >
    > Gareth
    >
    >
    > --
    > pianoman
    > ------------------------------------------------------------------------
    > pianoman's Profile:
    > http://www.excelforum.com/member.php...o&userid=33712
    > View this thread: http://www.excelforum.com/showthread...hreadid=544564
    >

+ 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