Late Binding Conversion to create log file

DCEXC

New Member
Joined
Oct 28, 2019
Messages
14
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
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
apologies, i had a silly moment and realised it was just missing the dim fs, ts as object
 
Upvote 0

Forum statistics

Threads
1,214,944
Messages
6,122,392
Members
449,081
Latest member
JAMES KECULAH

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