Saving the file automatically with the last person to close or view the file

bearcub

Well-known Member
Joined
May 18, 2005
Messages
732
Office Version
  1. 365
  2. 2013
  3. 2010
  4. 2007
Platform
  1. Windows
Is it possible to create a macro that will display in a cell the last person to view that file and to save it? Sometimes someone might open a file but doesn't make any changes. I was planning on turning on the track changes but I'm not sure if some of Excel's functionality is lost by doing this.

Plus, I would like to use a cell on the worksheet to notify the next user who opens the file to know who just worked on it (and perhaps the day and time?

Can VBA do this?

Michael
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Hi,

try something like this.
It will check if a sheet exist or else creates one, and insert username, filesize and a date/time stamp of the save action in a table.

Copy the code onto the "this Workbook" section of the workbook.

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
   
    Dim i As Integer, blnFound As Boolean
    blnFound = False
    
    Application.ScreenUpdating = False
    
    With ThisWorkbook
        For i = 1 To .Sheets.Count
            If .Sheets(i).Name = "Log-Info" Then
                blnFound = True
                Exit For
            End If
        Next i
        
        If blnFound = False Then
            .Sheets.Add
            With ActiveSheet
                .Name = "Log-Info"
                Cells(1, 1).Value = "Date & Time Stamp"
                Cells(1, 2).Value = "Saved By User"
                Cells(1, 3).Value = "File Size"
            End With
        End If
    End With
       
    Sheets("Log-Info").Select
    Range("A2:c2").Insert Shift:=xlDown

    Cells(2, 1).Value = Date + Time
    Cells(2, 1).NumberFormat = "dd/mm/yy hh:mm"
    Cells(2, 2).Value = Application.UserName
    Cells(2, 3).Value = (FileLen((ThisWorkbook.Path) & "\" & (ThisWorkbook.Name)) / 1024)
    ThisWorkbook.Worksheets("Log-Info").Cells.EntireColumn.AutoFit

    Application.ScreenUpdating = True

End Sub

Hope this helps.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top