Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: Userform, worksheet protection

  1. #1
    Board Regular
    Join Date
    Mar 2002
    Location
    Arkansas
    Posts
    358
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi All, Is there anyway of having a form on open, that if the user does not enter the correct code say (data), that I could have a message (Access denied) and the workbook would automatically close? Thx Dan.

  2. #2
    New Member
    Join Date
    Feb 2002
    Location
    Washington State
    Posts
    33
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    You need a userform (obviously) with a text box and one command button. Modify the names as needed.

    Add the following code to the workbook open event. Right click on the Excel icon on the extreme left side of the toolbar and choose "View Code"

    Private Sub Workbook_Open()
    UserForm1.Show
    End Sub

    Add this code to the userform module.

    Private Sub CommandButton1_Click()
    If TextBox1 <> "data" Then
    Application.DisplayAlerts = False
    MsgBox "Invalid Password - Excel will now close", vbExclamation, "Invalid Password"
    Application.Quit
    Application.DisplayAlerts = True
    Else
    Unload Me ' Unloads the userform and allows acess to the workbook.
    End If
    End Sub

    The following code disables the "X" on the userform to prevent closing it that way. This would be placed in the userform module as well.

    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)

    If CloseMode = vbFormControlMenu Then
    Cancel = True
    End If
    End Sub

    There are many other ways to add layers of protection to a workbook, but they are all basically like a padlock...they will only keep honest people honest. If someone wants into the file bad enough there is almost always a way around any protection.

    Hope this helps,

    Rick


    [ This Message was edited by: RWinfield on 2002-04-20 23:05 ]

    [ This Message was edited by: RWinfield on 2002-04-20 23:06 ]

  3. #3
    Board Regular
    Join Date
    Mar 2002
    Location
    Arkansas
    Posts
    358
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Thanks RWinfield, Works great. Im sure, like you said, anyone that wants in bad enough will get in. But Atleast this will help keeping the average user honest. Thanks again & have a good day. Dan

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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