Windows Programming - Programmers Heaven

Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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?

Comments

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

    [code]
    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
    [/code]

    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:

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

    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] http://support.microsoft.com/kb/161394 [/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.