+ Reply to Thread
Results 1 to 3 of 3

Protect and Track

  1. #1
    Registered User
    Join Date
    05-04-2004
    Posts
    15

    Exclamation Protect and Track

    Hi

    You guys are always helpful and so I know I've come to the right place. I'm trying to write code that protects and tracks a file, without using the shared workbook function in Excel.

    Here's what it does basically:

    1. When you open the file there are two command buttons - first one allows you to make changes to only certain parts of the file, while restricts changes to cells with formulas. Second one asks for a password and then allows you to make whatever changes you want, but tracks the changes.

    2. When you enter the password correctly, a value is entered into K1 so that Excel knows you are allowed to make changes to cells in that restricted range.

    3. When you make a change, the program undoes it, records what the old value was, asks for the new value in an input box, places the new value in the original cell and prints all the information on a tracking sheet

    My problem is that when the input box places the new value in the cell, the code keeps looping because its in that range and thinks it has to do the whole undo process again.

    I'm attaching sample code, its not complete yet, but here's the jist of it. The second part of the main if statement (track changes part) is what loops around endlessly. Maybe someone can tell me how to allow excel to accept the change. Thanks.

    If Sheet1.Cells(1, 11).Value = "" Then
    Application.EnableEvents = False
    If Not Intersect(Target, Range("LockedRange")) Is Nothing Then
    MsgBox "The action you just made to the following address is
    restricted and will be undone." & Target.Address
    Application.Undo
    End If
    Else
    ' Tracks changes made
    If Not Intersect(Target, Range("LockedRange")) Is Nothing Then
    Choice = MsgBox("Do you want to change this cell?", vbYesNo, "Warning")
    If Choice = vbYes Then
    Application.Undo
    CellLoc = ActiveCell.Address
    PreviousVal = ActiveCell.Formula
    Reason = InputBox("Please enter reason for change", "Important")
    NewVal = InputBox("Please enter new formula/ value here, followed by " = ":", "Note")
    ActiveCell.Formula = NewVal
    Sheet11.Cells(2, 1).Value = Date
    Sheet11.Cells(2, 2).Value = Application.UserName
    Sheet11.Cells(2, 3).Value = CellLoc
    Sheet11.Cells(2, 4).Value = PreviousVal
    Sheet11.Cells(2, 5).Value = NewVal
    Sheet11.Cells(2, 6).Value = Reason
    Else
    Application.Undo
    End If
    End If
    End If
    Last edited by Sheeny; 07-30-2007 at 04:09 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello Sheeny,

    Please follow the Forum rules for posting and remember to wrap your code using the # tags. You need to set the Application.EnableEvents = False before any other code (other than Dim statements) are executed.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

  3. #3
    Registered User
    Join Date
    05-04-2004
    Posts
    15
    Thank you so much!

+ 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