+ Reply to Thread
Results 1 to 2 of 2

Logging script

Hybrid View

  1. #1
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,309

    Re: Logging script

    Copy to the ThisWorkbook code module.
    Private Sub Workbook_Open()
        Dim lRow As Long
        Dim c As Range
        
        With Worksheets("Log")
            Set c = .Cells.Find(Application.UserName)
            If Not c Is Nothing Then
                lRow = c.Row
            Else
                lRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
            End If
            
            .Cells(lRow, 1) = "Opened"
            .Cells(lRow, 2) = Application.UserName
            .Cells(lRow, 3) = Format(Now, "dd-mm-yyyy hh:mm:ss")
        End With
    End Sub
    
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
        Dim lRow As Long
        Dim c As Range
        
        With Worksheets("Log")
            Set c = .Cells.Find(Application.UserName)
            If Not c Is Nothing Then
                lRow = c.Row
            Else
                lRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
            End If
            
            .Cells(lRow, 1) = "Closed"
            .Cells(lRow, 2) = Application.UserName
            .Cells(lRow, 3) = Format(Now, "dd-mm-yyyy hh:mm:ss")
        End With
        ThisWorkbook.Save
    End Sub
    Last edited by dangelor; 10-21-2022 at 12:05 PM. Reason: Different approach

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. script to run the macro from Vb script with out opening the excel file
    By chandanp in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-27-2021, 03:33 AM
  2. Need A Fast Script To Copy 80000 Cells But My Current Script Is Too Slow
    By Genus Max in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-20-2019, 09:54 AM
  3. calling the vb script from the shell script(unix platform)
    By chandanp in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-21-2014, 06:21 AM
  4. Integrating Mainframe emulator script with excel's vba script
    By Himanshu Mishra in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-07-2012, 10:30 AM
  5. Create VBA script to short, dedicated button in excel for script?
    By realized in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-01-2009, 11:54 PM
  6. Script that edits the text printed on the button that runs the script
    By petalred in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-18-2008, 02:41 PM

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