Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 10-14-2021, 03:03 PM
Logit Logit is offline Restrict editing by users in a shared workbook Windows 10 Restrict editing by users in a shared workbook Office 2007
Expert
 
Join Date: Jan 2017
Posts: 591
Logit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the rough
Default

Code:
Option Explicit

Private Sub Cancel_Click()

    Unload Me

End Sub

Private Sub OK_Click()

Dim c               As Object
Dim UserName        As String
Dim Password        As String
Dim MyError         As Integer
    
    'Assign UserName to a variable
    UserName = UserVerification.UserName.Text
    
    'Assign Password to a variable
    Password = UserVerification.Password.Text
    
    'Specify the sheet and range to look up the UserName
    With Sheets("UserNames").Range("A:A")
        Set c = .Find(What:=UserName, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=True)
    End With
    
    'If UserName cannot be found
    If c Is Nothing Then
        MsgBox "The username you have inputted is invalid, please try again.", vbCritical, "Incorrect UserName"
        Exit Sub
    End If
    
    'If Password is correct
    If Password = Sheets("UserNames").Range(c.Address).Offset(0, 1).Text Then
        ThisWorkbook.Unprotect Password:="Password"
                
        'If the sheet to make visible is not in the workbook an error will occur
        'If there is no error then make that sheet visible
        On Error Resume Next
        Sheets(Range(c.Address).Offset(0, 2).Text).Visible = True
        MyError = Err
        On Error GoTo 0
        ThisWorkbook.Protect Password:="Password", Structure:=True
        
        'If there was an error let the user know to try again.
        If MyError <> 0 Then
            MsgBox "The sheet specified could not be shown, please contact your system administrator.", vbCritical, "Sheet Specification Error"
            Exit Sub
        End If
        Else
        
        'If the password is incorrect let the user know to try again
        MsgBox "The password you have specified is incorrect, please try again.", vbCritical, "Incorrect Password"
        Exit Sub
    End If
    
    'Dismiss the userform
    Unload Me

End Sub

Private Sub UserForm_Initialize()
    Me.UserName.Value = "User"
End Sub
Attached Files
File Type: xls Multiple User Sheet Protection.xls (46.5 KB, 10 views)
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to restrict others from viewing PAST events for shared calendar? dylansmith Outlook 1 10-17-2018 05:03 AM
Restrict editing by users in a shared workbook Restrict ppt from editing wardma PowerPoint 3 05-02-2017 12:19 PM
Restrict editing by users in a shared workbook Could not remove Restrict editing markecb Word 4 02-18-2016 07:22 AM
Restrict editing by users in a shared workbook Restrict formatting and editing problem David141 Word 1 08-28-2014 05:18 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:33 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft