Windows Programming

I want to get a log file updated whenever a user changes an Excel Sheet.

i.e. say username Bill changed the Excel Sheet at time 12.30.00pm on 31st Jan 2009
I would like to get the text file updated with the user name and the date and time.

What is the best way/technology to do that?


  • Well if you wanted to update the logfile whenever a save takes place you could use the following code in VBA:

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

    Open "C:LogFile.txt" For Append As #1 'Opens logfile for editing
    Write #1, "User: " & Application.UserName ' Writes username
    Write #1, "Saved Changes at: " & Format(Now(), "dd/mm/yyyy hh:mm:ss AMPM") ' Writes timestamp
    Write #1, ' Write blank line.
    Close #1 ' Close file.

    End Sub

    Ofcourse you would just adjust that as necessary, have it all on one line or whatever. The only problem with above is that it goes on the username registered with MS Office and in large companies when installing MS Office most techs just leave something generic in there like 'User'. Another option would be to have the same code as above but add a prompt to the sub whereby the user would have to type their name in:

    Dim CurrUser As String
    CurrUser = InputBox(Prompt:="Your name:", _
    Title:="ENTER YOUR NAME", Default:="Your Name here")

    This ofcourse has one major downfall, you have to rely on people typing in their name. To get the windows username in there instead is obviously the best option but also the hardest, to attempt that you would need to read this article first:

    [green] [/green]

    Hope this helps, feel free to ask me anything. Dai
    Do or do not, there is no try. |
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion