How to track changes of a shared workbook in a separate workbook

Feroz90

Board Regular
Joined
Apr 25, 2019
Messages
52
Hi All,

Is there any chance to track the changes of a shared workbook in a separate workbook.

Since the workbook needs to be shared with 20 users and adding the code to the same workbook will slow down the file. Since the file consists of 10 excel sheets.

Please help in adding a code to separate workbook to track all the changes with the username, from, to and time.

Thanks
 

jkpieterse

Well-known Member
Joined
Dec 3, 2007
Messages
965
That wouldn't help, as the code would still have to work with the workbook in question and hence be running in the same instance of Excel.
 

gallen

Well-known Member
Joined
Jun 27, 2011
Messages
1,931
Does it need to be a separate workbook? A text file would do it, just depends how organised you need the change data.

Something like this works:

Firstly create a text file in a shared location and call it something like ChangeLog.txt

This code goes in the "ThisWorkbook" object

Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    RecordChange Target
End Sub


Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    sPreviousValue = CStr(Target.Value)
End Sub
Create a module and put this code in it, making sure you change the LogPath and LogName variables

Code:
Public sPreviousValue As String 'ensure this variable declaration is at the top of the module


Sub RecordChange(Target As Range)
    Dim LogPath As String, LogName As String
    Dim sUserName As String
    Dim sLog As String 'log text

    'Make sure you change these variables to suit
    LogPath = "C:\Test\" 
    LogName = "ChangeLog.txt"
    
    'get current, logged in, user
    sUserName = StrConv(Environ("UserName"), vbProperCase)
    
    sLog = sUserName & " | "
    sLog = sLog & "Workbook = " & ThisWorkbook.Name & " | "
    sLog = sLog & "Worksheet = " & ActiveSheet.Name & " | "
    sLog = sLog & "Previous Value = " & sPreviousValue & " | "
    sLog = sLog & "New Value = " & Target.Value & " | "
    sLog = sLog & Now
    
    Open LogPath & LogName For Append As [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] 
    
    Print [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] , sLog
    Close [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] 
    
End Sub
It isn't perfect but it does track changes
 

Forum statistics

Threads
1,081,574
Messages
5,359,704
Members
400,545
Latest member
Damntheman30

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top