+ Reply to Thread
Results 1 to 8 of 8

Tracking access to Excel file through VBA rutine

Hybrid View

  1. #1
    Valued Forum Contributor scaffdog845's Avatar
    Join Date
    02-01-2008
    Location
    Aston, PA. USA.
    MS-Off Ver
    Microsoft 365
    Posts
    375

    Tracking access to Excel file through VBA rutine

    Morning and Happy Holidays!

    I was looking for some help on a VBA solution. I would like to run an on open event for a scheduling workbook. It should open a logging workbook, write the %username% to the first blank line in A:A then save and close the logging workbook, leaving the scheduling workbook open and ready for input.

    The following UNC can be used as the location for the logging workbook.

    \\ComputerName\ParentFolder\ChildFolder\LogFiles

    If possible, I would like this logging to be transparent to the end user.

    As always thanks for the help and have a GREAT HOLIDAY SEASON!
    Last edited by scaffdog845; 12-28-2009 at 11:25 AM. Reason: Solved
    Click here to read the Forum Rules
    Whatever it is in life you decide to go after, go after with great ferocity.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Tracking access to Excel file through VBA rutine

    Maybe like this (untested):
    Private Sub Workbook_Open()
        Const sFile     As String = "\\ComputerName\ParentFolder\ChildFolder\LogFiles\someLogFile.xls"
    
        If Len(Dir(sFile)) Then
            Workbooks.Open sFile
            With ActiveWorkbook.Worksheets(1)
                .Cells(.Rows.Count, "A").End(xlUp).Offset(1).Value = Environ("username")
                .Close SaveChanges:=True
            End With
        Else
            MsgBox "Log file " & sFile & " not found."
        End If
    End Sub
    Last edited by shg; 12-23-2009 at 04:23 PM. Reason: corrected per subsequent posts
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Valued Forum Contributor scaffdog845's Avatar
    Join Date
    02-01-2008
    Location
    Aston, PA. USA.
    MS-Off Ver
    Microsoft 365
    Posts
    375

    Re: Tracking access to Excel file through VBA rutine

    SHG

    Merry Texmas to you too!

    Thanks for the try but I don't belive anything is happening with this code.

    I tested with a new .xlsm workbook and added your code as a module.

    The logfile to write to is named
    Daily Schedule Access Logfile.xlsx
    and is located in the
    \\fspbrf01\GROUP\Maintenance\Work Management\Public\Work Management  KPIs\SAP Scheduling\Schedule logfile\
    directory. The extra space between Management & KPIs is not a typo, it was how the directory structure was created long before I got here.

    Your code has been edited to match the actual directory structure and work book name.
    Private Sub Workbook_Open()
        Const sFile     As String = "\\fspbrf01\GROUP\Maintenance\Work Management\Public\Work Management  KPIs\SAP Scheduling\Schedule logfile\Daily Schedule Access Logfile.xlsx"
    
        If Len(Dir(sFile)) Then
            Workbooks.Open sFile
            With ActiveWorkbook.Worksheets(1)
                .Cells(.Rows.Count, "A").End(xlUp).Offset(1).Value = Environ("username")
                .Close SaveChange:=True
            End With
        Else
            MsgBox "Log file " & sFile & " not found."
        End If
    End Sub
    Nothing is being written to "Daily Schedule Access Logfile.xlsx" nor is a message box reporting any errors even if I temporarily remove the "Daily Schedule Access Logfile.xlsx" file.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Tracking access to Excel file through VBA rutine

    So you single-step through the code, and what happens?

  5. #5
    Valued Forum Contributor scaffdog845's Avatar
    Join Date
    02-01-2008
    Location
    Aston, PA. USA.
    MS-Off Ver
    Microsoft 365
    Posts
    375

    Re: Tracking access to Excel file through VBA rutine

    I had to figure out how to single step through code. I'm getting a Run-time error '438': Object doesn't support this property or method on .
    Close SaveChange:=True
    It did open the file and log the username as expected.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Tracking access to Excel file through VBA rutine

    .Close SaveChanges:=True
    That was among the untested parts

    Corrected in prior post for future generations ...

    Also, note it's .Close, not Close

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1