+ Reply to Thread
Results 1 to 2 of 2

unlocking with username and autolocking when save

Hybrid View

angel2903 unlocking with username and... 02-13-2014, 10:14 AM
slx Re: unlocking with username... 02-13-2014, 10:50 AM
  1. #1
    Registered User
    Join Date
    01-28-2014
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    44

    unlocking with username and autolocking when save

    Hi all,

    I found this code on the forum posted yesterday by another user. the post is as follows


    Excel can automatically recognise individuals by their windows login name so you can fully automate the protect/unprotect of the correct sheets without even individuals having to use passwords.

    The first step though would be to gather the id's of all users.

    1. Create an additional sheet and call it UserLog
    2. Put the following code into all the worksheet code modules



    
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim EndRow As Long
        If Target.Cells.Count > 1 Then Exit Sub
        EndRow = Sheets("UserLog").Cells(Rows.Count, "A").End(xlUp).Row + 1
        Sheets("UserLog").Range("A" & EndRow).Value = ActiveSheet.Name
        Sheets("UserLog").Range("B" & EndRow).Value = Environ("UserName")
    End Sub
    Once you know the windows login names and which sheet they are responsible for you can add the following code to each worksheet



    
    Private Sub Worksheet_Activate()
        If Environ("Username") = "Andy" Then
            ActiveSheet.Unprotect Password:="mypass"
        Else
            ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFiltering:=True, Password:="mypass"
        End If

    End SubLast edited by AndyLitch; Yesterday at 01:16 AM.

    I have tried as per below and it is not working.

    I have about 50 user that uses one document and will record their comments to instructions, but only 20 users will be able to add the instructions. The document needs to autolock when it is saved and can only be unlock with the username of the 20 users.

  2. #2
    Forum Contributor
    Join Date
    04-24-2007
    Location
    NYC
    MS-Off Ver
    2k3/2k7/2010
    Posts
    270

    Re: unlocking with username and autolocking when save

    Environ Username refers to your Windows account name.

+ 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] Username and Password Form - Show Username in Sheet
    By ryan180 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-24-2013, 07:06 PM
  2. Unlocking Chart Axis Title under locked sheet without unlocking the sheet
    By dalelengle in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-16-2012, 08:59 PM
  3. [SOLVED] how to add username to file name on save
    By tinkerbelle in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-20-2012, 03:53 PM
  4. Save to a path that requires username and password
    By brl8 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-30-2011, 06:00 PM
  5. Macro Unlocking
    By ggovensky in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-17-2010, 03:27 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