Avatar of Kevin Buckland
Kevin Buckland
Flag for United States of America asked on

Excel formula to report date modified

I have an Excel file (Daily Asset Allocation Report.xlsx) and I would like an Excel formula or script which reports (in cell D23, "Start Here" worksheet) the date and time that another Excel file was last modified.  

The filename/path of the file that I want to have Excel report the modified date for is always I:\Interfund Transfers\Interfund Transfer.xlsx.  

Thank you.
Microsoft OfficeVBAMicrosoft ExcelVB Script

Avatar of undefined
Last Comment
Kevin Buckland

8/22/2022 - Mon
Paul Cook-Giles

here you go:

Worksheets("Start Here").Range("D23") = FileDateTime("I:\Interfund Transfers\Interfund Transfer.xlsx")

:)
Kevin Buckland

ASKER
Sorry I know just enough to be dangerous... Can you tell me how and where to put this code?

Thank you
Paul Cook-Giles

LOL... of course!  Do you know how to record a macro?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Kevin Buckland

ASKER
Yes, I can record a macro.
Paul Cook-Giles

1. Open the workbook in which you want the date check  to run.  The "Record Macro" window will open.
2.  Start recording a macro;  name it "CheckInterfundTransfer.xlsxDate"  (or something;  you just need to be able to recognize it).
3.  Give it a shortcut key.
4.  Confirm the macro will be stored in "This Workbook"
5.  Click OK.

type a couple of letters, then stop recording.

6.  Press Alt-F11. The Microsoft Visual Basic for Applications window will open.  Find the macro you just recorded.
7.  There will be a line that looks something like this
                     ActiveCell.FormulaR1C1 = "abc"   (or whatever letters you typed)
delete that line, and paste
                     Worksheets("Start Here").Range("D23") = FileDateTime("I:\Interfund Transfers\Interfund Transfer.xlsx")

8.  Close the Microsoft Visual Basic for Applications window, and return to your workbook.
9.  Press the shortcut keys;  Start Here.D23 should be populated with the date and time of the last update.

Let me know if you get stuck.  :)
Kevin Buckland

ASKER
OK, I'm getting a compile error: Invalid Outside Procedure.  It highlighted "I:\Interfund Transfers\Interfund Transfer.xlsx"
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Paul Cook-Giles

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Shums Faruk

I got something which will show you on Msg but I am still trying to get into Workbook Log:
Sub GetDate()

    Dim oFS As Object
    Dim strFilename As String

    'Put your filename here
    strFilename = "I:\Interfund Transfers\Interfund Transfer.xlsx"


    'This creates an instance of the MS Scripting Runtime FileSystemObject class
    Set oFS = CreateObject("Scripting.FileSystemObject")

    MsgBox strFilename & " was created on " & oFS.GetFile(strFilename).DateCreated & " was last modified on " & oFS.GetFile(strFilename).Datelastmodified



    Set oFS = Nothing

End Sub

Open in new window

Shums Faruk

This is another approach to get on D23, but it can't get log of modification:
Sub GetDate()

    Dim oFS As Object
    Dim strFilename As String

    'Put your filename here
    strFilename = "I:\Interfund Transfers\Interfund Transfer.xlsx"


    'This creates an instance of the MS Scripting Runtime FileSystemObject class
    Set oFS = CreateObject("Scripting.FileSystemObject")

    Cells(23, 4) = strFilename & " was created on " & oFS.GetFile(strFilename).DateCreated & " was last modified on " & oFS.GetFile(strFilename).Datelastmodified



    Set oFS = Nothing

End Sub

Open in new window

Shums Faruk

Check this with only Date & Time of Last Modification on D23:
Sub GetDate()

    Dim oFS As Object
    Dim strFilename As String

    'Put your filename here
    strFilename = "I:\Interfund Transfers\Interfund Transfer.xlsx"


    'This creates an instance of the MS Scripting Runtime FileSystemObject class
    Set oFS = CreateObject("Scripting.FileSystemObject")

    Cells(23, 4) = oFS.GetFile(strFilename).Datelastmodified

    Set oFS = Nothing

End Sub

Open in new window

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Shums Faruk

Here you go...
Click on Update Result. You will get first date and time of your file. Open your source file / save / close, then click update result again, your second date and time will be update on top of the row. This way you can keep the log of your file, since last updated.
Sub GetDate()
Dim FSO As Object
Dim SourceFolder As String
Dim FileName As String
Dim Ws As Worksheet
Dim LR As Long
Set Ws = Worksheets("Sheet1")
LR = Ws.Range("B" & Rows.Count).End(xlUp).Row

SourceFolder = Ws.Range("B4").Value
Set FSO = CreateObject("Scripting.FileSystemObject")
FileName = SourceFolder & Ws.Range("B6").Value

Ws.Cells(8, 2) = FSO.GetFile(FileName).Datelastmodified

Set FSO = Nothing

If Ws.Cells(8, 2).Value = Ws.Cells(12, 2).Value Then
    Ws.Cells(12, 2).Value = Ws.Cells(8, 2).Value
    Ws.Range("A12:A" & LR).FormulaR1C1 = "=MAX(R11C1:R[-1]C)+1"
    Ws.Range("A12:A" & LR).Value = Ws.Range("A12:A" & LR).Value
Else
    Ws.Cells(12, 2).EntireRow.Insert Shift:=xlDown
    Ws.Cells(12, 2).Value = Ws.Cells(8, 2).Value
    Ws.Range("A12:A" & LR + 1).FormulaR1C1 = "=MAX(R11C1:R[-1]C)+1"
    Ws.Range("A12:A" & LR + 1).Value = Ws.Range("A12:A" & LR + 1).Value
End If
Ws.Range("A10").Select
End Sub

Open in new window

Please find attached for your reference.
Daily-Asset-Allocation-Report.xlsm
Shums Faruk

If you want to change the path - change in B4, and if you want to change the file name change the full filename with extension in B6. You can Keep log of any file by saving above workbook with another log book name.
Paul Cook-Giles

Kevin, I'm reposting this in case you didn't see it earlier.  :)  
P

When you look at the VBA window, the macro should look like this:
Sub CheckInterfundTransferDate()
'
' MacrCheckInterfundTransferDateo2 Macro
'
' Keyboard Shortcut: Ctrl+Shift+C
Worksheets("Start Here").Range("D23") = FileDateTime("I:\Interfund Transfers\Interfund Transfer.xlsx")
End Sub

Open in new window

If that's not the way it looks, and you can't get it to work, copy and paste the macro you created.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Kevin Buckland

ASKER
Thanks much, works like a charm!