Track users who use excel file

ShieBoon

Board Regular
Joined
May 3, 2011
Messages
111
Hello, do you guys know of any code that can allow me to track the users who use a shared excel file and log the records in a worksheet within the file?

i'm using xl 2003
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Hey vog, that has helped. Thanks for the reply too. Anw i have a question regarding the codes.

Dim LR As Long
If Sh.Name = "Log" Then Exit Sub
Application.EnableEvents = False
With Sheets("Log")
LR = .Range("A" & Rows.Count).End(xlUp).Row
.Range("A" & LR + 1).Value = Now
.Range("B" & LR + 1).Value = Sh.Name
.Range("C" & LR + 1).Value = Target.Address(False, False)
.Range("D" & LR + 1).Value = Target.Value
End With
Application.EnableEvents = True

Why do we need to disable the events?

Thanks,
Shie Boon
 
Upvote 0
It is just to ensure that the event code is not called needlessly when the macro writes to (changes) the Log sheet.
 
Upvote 0
Hi VoG,

I would like to use tihs code in one of my reports, is it possible to exclude certain cells from being included? I have a range called "Data" that I would like to exclude.

Also is it possible for the previous contents before the change to be included? so there is a before and after.

Regards Damian
 
Upvote 0
Hi VoG,

I would like to use tihs code in one of my reports, is it possible to exclude certain cells from being included? I have a range called "Data" that I would like to exclude.

Also is it possible for the previous contents before the change to be included? so there is a before and after.

Regards Damian

Can you post the code that you want to use - there are several versions in that thread.
 
Upvote 0
Hi,

Here is the code

Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim LR As Long
If Sh.Name = "Log" Then Exit Sub
Application.EnableEvents = False
With Sheets("Log")
    LR = .Range("A" & Rows.Count).End(xlUp).Row
    .Range("A" & LR + 1).Value = VBA.Environ("username")
    .Range("B" & LR + 1).Value = Now
    .Range("C" & LR + 1).Value = Sh.Name
    .Range("D" & LR + 1).Value = Target.Address(False, False)
    .Range("E" & LR + 1).Value = Target.Value
End With
Application.EnableEvents = True
End Sub

Regards
 
Upvote 0
Try (untested)

Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim LR As Long, NewVal As Variant, OldVal As Variant
If Sh.Name = "Log" Then Exit Sub
If Not Intersect(Target, Range("Data")) Is Nothing Then Exit Sub
Application.EnableEvents = False
NewVal = Target.Value
Application.Undo
OldVal = Target.Value
Target.Value = NewVal
With Sheets("Log")
    LR = .Range("A" & Rows.Count).End(xlUp).Row
    .Range("A" & LR + 1).Value = VBA.Environ("username") 'user
    .Range("B" & LR + 1).Value = Now 'date and time
    .Range("C" & LR + 1).Value = Sh.Name 'sheet
    .Range("D" & LR + 1).Value = Target.Address(False, False) 'cell
    .Range("E" & LR + 1).Value = OldVal 'previous value
    .Range("F" & LR + 1).Value = Target.Value 'new value
End With
Application.EnableEvents = True
End Sub
 
Upvote 0
Hi,

Tried it and it is not doing anything, nothing is being entered onto the Log sheet.

Regards
 
Upvote 0
Now tested and working. Make sure that macros are enabled and that Events are enabled. For Events, in the code window press CTRL + G, type in

Application.EnableEvents=True

and press Enter.

Then try again.
 
Upvote 0

Forum statistics

Threads
1,215,430
Messages
6,124,846
Members
449,194
Latest member
HellScout

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top