Display last time another file was updated

act2106

New Member
Joined
Jun 9, 2011
Messages
13
I'm trying to display the last time a file was updated using:

Code:
Function LastSavedTime(WBName As String) As Date  Dim wb As Workbook
  Set wb = Workbooks(WBName)
  LastSavedTime = wb.BuiltinDocumentProperties("Last Save Time")
End Function

In cell A2 is a file path and name. In cell B2 I typed "=LastSavedTime(A2)", and the result is a #VALUE error. What am I doing wrong?
 
Last edited:

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
I don't think you can use that code for a workbook outside of what you are using. I did however find the following code which might help?
Code:
Option Explicit

Private Function LastModified(ByRef filePath As String) As Date
    'Set a default value
    LastModified = vbNull

    If Len(Trim$(filePath)) = 0 Then Exit Function

    With CreateObject("Scripting.FileSystemObject")
        If .FileExists(filePath) Then LastModified = .GetFile(filePath).DateLastModified
    End With

End Function

Sub SOExample()
    'Specify a path to a file you want to get LastModified Date
    Dim filePath As String: filePath = Worksheets("Sheetname").Cells(2, 1).Value

    'Return a date or vbNull
    Dim myDate As Date: myDate = LastModified(filePath)

    'Output the Date if it isn't vbNull
    If Not myDate = vbNull Then MsgBox myDate
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,526
Messages
6,114,122
Members
448,550
Latest member
CAT RG

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