Im in desperate need to create a hidden log file that keeps track of user changes, and cant quite pin down the correct way to code it. i did find something which i think might work, however i need it to be late binding as im developing a program for work and cant go to every computer to switch on the references.
here is the code i found from a thread on this site.
Logging.LogEvent "Name me whatever you'd like", Application.username
Hope this helps
Function LogEvent(EventName As String, Info As String)
Set FS = CreateObject("Scripting.FileSystemObject")
Set TS = FS.OpenTextFile("C:\Logs\NameMe.txt", 8, True)
TS.WriteLine expandString(Now, 30, "L") & " " & expandString(EventName, 30, "L") & " " & expandString(Info, 250, "L")
TS.Close
Set TS = Nothing
Set FS = Nothing
End Function
Function expandString(ipString As String, Length As Integer, Optional Justify As String = "L") As String
Dim strLength As Integer
Dim Spaces As String
strLength = Len(ipString)
If strLength > Length Then
expandString = Left(ipString, Length)
ElseIf strLength = Length Then
expandString = ipString
Else
Spaces = String(Length - strLength, " ")
If UCase(Left(Justify, 1)) = "R" Then
expandString = Spaces & ipString
Else
expandString = ipString & Spaces
End If
End If
End Function
here is the code i found from a thread on this site.
Excel VBA AUDIT LOG
Hi Guys, I have been trying to create a VBA change log for days now, without any luck whatsoever. I have a workbook that contains several sheets, and I want to log every change that is made to a cell within the workbook The information I want to log: Username (excel username), Date, Time...
www.mrexcel.com
Logging.LogEvent "Name me whatever you'd like", Application.username
Hope this helps
Function LogEvent(EventName As String, Info As String)
Set FS = CreateObject("Scripting.FileSystemObject")
Set TS = FS.OpenTextFile("C:\Logs\NameMe.txt", 8, True)
TS.WriteLine expandString(Now, 30, "L") & " " & expandString(EventName, 30, "L") & " " & expandString(Info, 250, "L")
TS.Close
Set TS = Nothing
Set FS = Nothing
End Function
Function expandString(ipString As String, Length As Integer, Optional Justify As String = "L") As String
Dim strLength As Integer
Dim Spaces As String
strLength = Len(ipString)
If strLength > Length Then
expandString = Left(ipString, Length)
ElseIf strLength = Length Then
expandString = ipString
Else
Spaces = String(Length - strLength, " ")
If UCase(Left(Justify, 1)) = "R" Then
expandString = Spaces & ipString
Else
expandString = ipString & Spaces
End If
End If
End Function