We help IT Professionals succeed at work.

Excel formula to report date modified

539 Views
Last Modified: 2017-03-22
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

Paul Cook-GilesSenior Application Developer
CERTIFIED EXPERT

Commented:
here you go:

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

:)

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
CERTIFIED EXPERT

Commented:
LOL... of course!  Do you know how to record a macro?

Author

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

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.  :)

Author

Commented:
OK, I'm getting a compile error: Invalid Outside Procedure.  It highlighted "I:\Interfund Transfers\Interfund Transfer.xlsx"
Senior Application Developer
CERTIFIED EXPERT
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
ShumsManaging Director/Excel VBA Developer
CERTIFIED EXPERT
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
CERTIFIED EXPERT
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
CERTIFIED EXPERT
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
CERTIFIED EXPERT
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
CERTIFIED EXPERT
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
CERTIFIED EXPERT

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.

Author

Commented:
Thanks much, works like a charm!

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions