Consulting

Results 1 to 2 of 2

Thread: Excel Access Log VBA

  1. #1
    VBAX Newbie
    Joined
    May 2012
    Posts
    1
    Location

    Exclamation Excel Access Log VBA



    I'm trying to record users who access excel documents.

    However instead of recording the data in a seperate sheet in the same workbook, i want the data to log in a completely different workbook.

    Is this possible?

    The code i have as my starting point is:

    Private Sub Workbook_Open()
    Sheets("Access log").Activate
    If Range("A1").Value = "" Then
    n = 1
    Else
    n = Cells(Rows.Count, "A").End(xlUp).Row + 1
    End If
    Cells(n, "A").Value = Environ("username")
    Cells(n, "b").Value = Date
    Cells(n, "c").Value = Time
    ActiveWorkbook.Save
    Sheets("Access log").Activate
    End Sub

    Any help would be appreciated!

  2. #2
    VBAX Mentor
    Joined
    Feb 2009
    Posts
    493
    Location
    [VBA]Private Sub Workbook_Open()
    Dim lngFile As Long
    dim strFilename as string
    lngFile = FreeFile

    strfilename = "C:\Logfile.txt"

    Open strFilename For Append As lngFile

    Print #lngFile, Environ("username"); ";";
    Print #lngFile, format(date(),"YYYYMMDD"); ";";
    Print #lngFile, format(Now(),"HHMMSS")


    Close lngFile
    end sub
    [/VBA]

    This will write a log to a text file. Perhaps this would be a solution for you.
    -----------------------------------------
    The more you learn about something the more you know you have much to learn.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •