+ Reply to Thread
Results 1 to 2 of 2

UserForm That Brings Specific Worksheet Up, Hides All Else

Hybrid View

  1. #1
    Registered User
    Join Date
    08-31-2016
    Location
    North Dakota
    MS-Off Ver
    Windows 7/ Office Professional
    Posts
    1

    Lightbulb UserForm That Brings Specific Worksheet Up, Hides All Else

    Hello,

    Im trying to make something that will bring up one specific worksheet when a username and password is entered, and only that sheet. I am running into problems where It opens the last saved worksheet can be seen in the background until you enter the username/password. Additionally, it will only show the correct worksheet after you click on the tabs, then runs a "You cant do that" message for every other tab.

    I want to make this as simple as a I can so that it simply bring us ONE worksheet automatically when they enter their username/password. can anyone help me out?

    This is the code in the Workbook:

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
        Dim w As Worksheet
        Dim bSaveIt As Boolean
    
        bSaveIt = False
        For Each w In Worksheets
            If w.Visible Then
                Select Case w.Name
                    Case "akduen1"
                        w.Protect ("akduen1")
                        w.Visible = False
                        bSaveIt = True
                    Case "alkewle"
                        w.Protect ("alkewle")
                        w.Visible = False
                        bSaveIt = True
                    Case "jrriepe"
                        w.Protect ("jrriepe")
                        w.Visible = False
                        bSaveIt = True
                    Case "ktwoode"
                        w.Protect ("ktwoode")
                        w.Visible = False
                        bSaveIt = True
                    Case "mastr01"
                        w.Protect ("mastr01")
                        w.Visible = False
                        bSaveIt = True
                    Case "mrrud"
                        w.Protect ("mrrud")
                        w.Visible = False
                        bSaveIt = True
                    Case "wlgood"
                        w.Protect ("wlgood")
                        w.Visible = False
                        bSaveIt = True
                    Case "manager"
                    If txtPass.Text <> "coffee" Then bError = True
                Application.EnableEvents = False
                End Select
            End If
        Next w
        If bSaveIt Then
            ActiveWorkbook.CustomDocumentProperties("auth").Delete
            ActiveWorkbook.Save
        End If
    End Sub
    
    Private Sub Workbook_Open()
        UserForm1.Show
    End Sub
    
    Private Sub Workbook_SheetActivate(ByVal Sh As Object)
        If Sh.Name <> "Main" Then
            If Sh.Name <> ActiveWorkbook.CustomDocumentProperties("auth").Value Then
                Sh.Visible = False
                MsgBox "You Can't Do That, Sorry."
            End If
        End If
    End Sub

    This is the code in the User Form:

    Private Sub btnOK_Click()
        Dim bError As Boolean
        Dim sSName As String
        Dim p As DocumentProperty
        Dim bSetIt As Boolean
    
        bOK2Use = False
        bError = True
        If Len(txtUser.Text) > 0 And Len(txtPass.Text) > 0 Then
            bError = False
            Select Case txtUser.Text
                Case "akduen1"
                    sSName = "akduen1"
                    If txtPass.Text <> "akduen1" Then bError = True
                 Case "alkewle"
                    sSName = "alkewle"
                    If txtPass.Text <> "alkewle" Then bError = True
                Case "jrriepe"
                    sSName = "jrriepe"
                    If txtPass.Text <> "jrriepe" Then bError = True
                 Case "ktwoode"
                    sSName = "ktwoode"
                    If txtPass.Text <> "ktwoode" Then bError = True
                Case "mastr01"
                    sSName = "mastr01"
                    If txtPass.Text <> "mastr01" Then bError = True
                 Case "mrrud"
                    sSName = "mrrud"
                    If txtPass.Text <> "mrrud" Then bError = True
                Case "wlgood"
                    sSName = "wlgood"
                    If txtPass.Text <> "wlgood" Then bError = True
                Case "admin"
                    If txtPass.Text <> "coffee" Then bError = True
                Application.EnableEvents = False
             End Select
        End If
        If bError Then
            MsgBox "Invalid UserID or Password"
        Else
            
                    
            bOK2Use = True
            Unload UserForm1
    End If
    End Sub
    Private Sub UserForm_Terminate()
        If Not bOK2Use Then
            ActiveWorkbook.Close (False)
        End If
    End Sub

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: UserForm That Brings Specific Worksheet Up, Hides All Else

    Any chance you could upload a sample workbook?

    Click on GO ADVANCED, scroll down and click Manage Attachments.
    If posting code please use code tags, see here.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Enter data into a userform text box to show in a specific cell in a specific worksheet
    By Stevecraig211 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-10-2016, 10:02 AM
  2. Send to Excel brings up blank worksheet.
    By dflak in forum Excel General
    Replies: 2
    Last Post: 03-10-2016, 03:23 PM
  3. Replies: 7
    Last Post: 03-10-2013, 07:56 PM
  4. Checkbox When Unchecked Hides Worksheet
    By dcarn in forum Excel General
    Replies: 1
    Last Post: 12-06-2012, 06:57 PM
  5. Transfer specific data on specific worksheet using userform
    By kriscar_44 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-17-2010, 04:03 AM
  6. Userform that hides/unhides worksheets
    By fecurtis in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-20-2008, 09:36 AM
  7. Replies: 3
    Last Post: 03-09-2007, 05:11 AM

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