If a particular person changes a workbook email me

gruple

New Member
Joined
Dec 5, 2005
Messages
8
I need to know if a particular employee tries to make changes to a workbook that I don't want him to. I cannot limit him from accessing it because of our IT policy. Is there a way to email me if or when he makes a change? Or is there a way to highlight it or something? Thanks for the help.
 

Some videos you may like

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

lozzablake

Well-known Member
Joined
Dec 15, 2005
Messages
818
There are two parts of this code. The first must be pasted in a normal module and is a function that gets the user id of the person logged onto the network:

Code:
Option Explicit

'******************** Code Start **************************
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
    strUserName = String$(254, 0)
    lngLen = 255
    lngX = apiGetUserName(strUserName, lngLen)
    If (lngX > 0) Then
        fOSUserName = Left$(strUserName, lngLen - 1)
    Else
        fOSUserName = vbNullString
    End If
End Function

The second part goes into the sheetChange event of the workbook. Everytime a sheet is changed it will send a copy of the workbook to the recipient. Note you may end up with a full inbox if the user makes a lot of changes. (you could change this to the workbook open event and then you receive it only whe the specified user open the workbook). Obviously you can put something else in the IF clause to reflect what you want to do:

Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
     If fOSUserName() = "User to Check" Then
        ThisWorkbook.SendMail Recipients:="John Smith" 'replace with your e-mail name

     End If
     
     
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,113,990
Messages
5,545,365
Members
410,679
Latest member
rolandbianco
Top