Excel formula to report date modified

Kevin Buckland
Kevin Buckland used Ask the Experts™
on
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.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Paul Cook-GilesSenior Application Developer

Commented:
here you go:

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

:)
Kevin BucklandInvestment Officer

Author

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

Thank you
Paul Cook-GilesSenior Application Developer

Commented:
LOL... of course!  Do you know how to record a macro?
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Kevin BucklandInvestment Officer

Author

Commented:
Yes, I can record a macro.
Paul Cook-GilesSenior Application Developer

Commented:
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 BucklandInvestment Officer

Author

Commented:
OK, I'm getting a compile error: Invalid Outside Procedure.  It highlighted "I:\Interfund Transfers\Interfund Transfer.xlsx"
Senior Application Developer
Commented:
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.
ShumsManaging Director/Excel VBA Developer
Distinguished Expert 2018

Commented:
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

ShumsManaging Director/Excel VBA Developer
Distinguished Expert 2018

Commented:
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

ShumsManaging Director/Excel VBA Developer
Distinguished Expert 2018

Commented:
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

ShumsManaging Director/Excel VBA Developer
Distinguished Expert 2018

Commented:
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
ShumsManaging Director/Excel VBA Developer
Distinguished Expert 2018

Commented:
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-GilesSenior Application Developer

Commented:
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.
Kevin BucklandInvestment Officer

Author

Commented:
Thanks much, works like a charm!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial