Results 1 to 1 of 1

Turn Audit Trail on and off

Threaded View

  1. #1
    Registered User
    Join Date
    04-07-2014
    Location
    St Albans, VT
    MS-Off Ver
    Excel 2013
    Posts
    2

    Turn Audit Trail on and off

    I am looking to only use the audit trail vba code when a command button is used. I have the following two options for audit trails - the first does not collect all of the information when used as a macro and the second gives an error for the target. Is it possible to selectively use code when it is assigned to a worksheet?

    Dim vOldVal
    'Must be at top of module
    
    Private Sub Workbook_SheetChange(ByVal sh As Object, ByVal Target As Range)
    Dim bBold As Boolean
    If Target.Cells.Count > 1 Then Exit Sub
    On Error Resume Next
        With Application
             .ScreenUpdating = False
             .EnableEvents = False
        End With
        If IsEmpty(vOldVal) Then vOldVal = "Empty Cell"
        bBold = Target.HasFormula
            With Sheets("Log")
                .Unprotect Password:=""
                    If .Range("A1") = vbNullString Then
                       .Range("A1:E1") = Array("CELL CHANGED", "OLD VALUE", "NEW VALUE", "TIME OF CHANGE", "DATE OF CHANGE")
                    End If
              With .Cells(.Rows.Count, 1).End(xlUp)(2, 1)
                      .Value = Target.Address
                      .Offset(0, 1) = vOldVal
                          With .Offset(0, 2)
                            If bBold = True Then
                              .ClearComments
                              .AddComment.Text Text:="OzGrid.com:" & Chr(10) & "" & Chr(10) & "Bold values are the results of formulas"
                            End If
                              .Value = Target
                              .Font.Bold = bBold
                         End With
                    .Offset(0, 3) = Time
                    .Offset(0, 4) = Date
                End With
                .Cells.Columns.AutoFit
                .Protect Password:=""
            End With
        vOldVal = vbNullString
        With Application
             .ScreenUpdating = True
             .EnableEvents = True
        End With
    On Error GoTo 0
    End Sub
    
    Private Sub Workbook_SheetSelectionChange(ByVal sh As Object, ByVal Target As Range)
    vOldVal = Target
    End Sub
    Here is the second one:
    Dim PreviousValue
    
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target.Value <> PreviousValue Then
            Sheets("log").Cells(65000, 1).End(xlUp).Offset(1, 0).Value = _
                Application.UserName & " changed cell " & Target.Address _
                & " from " & PreviousValue & " to " & Target.Value & " at " & Time
        End If
    End Sub
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        PreviousValue = Target.Value
    End Sub
    Last edited by JBeaucaire; 07-23-2016 at 02:19 AM. Reason: Added missing CODE tags. Please read and follow the Forum Rules, link above in the menu bar. Thanks.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Audit Trail
    By Moggzzz in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-29-2016, 06:48 AM
  2. VBA code for audit trail issue
    By TheGrinch1 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-11-2015, 08:06 AM
  3. Pseudo-audit trail for unlocking a doc?
    By Gunther Maplethorpe in forum Excel General
    Replies: 1
    Last Post: 01-15-2014, 02:42 PM
  4. Audit Trail
    By jenziepie in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-01-2013, 01:56 PM
  5. Excel Audit Trail?
    By jvest0648 in forum Excel General
    Replies: 1
    Last Post: 12-17-2011, 02:57 PM
  6. Track Changes - Audit Trail
    By ChemistB in forum Excel General
    Replies: 2
    Last Post: 10-27-2006, 02:16 PM
  7. [SOLVED] Audit Trail
    By Pendelfin in forum Excel General
    Replies: 1
    Last Post: 01-23-2006, 11:10 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