Get last modified date

apinel

New Member
Joined
Aug 2, 2011
Messages
9
I have an excel spreadsheet with multiple file names (including file path) listed in a column. I have to update other files using these 'underlying' files. So each cell has the file path and file name (i.e. Q:\Folder\File Name.xls). I would like to have the adjacent cells indicate the last modified date for each file. This saves me time from looking for the last modified date manually across different folders in my servers to see if the 'underlying' file has been updated, which I would need in order to update my other files. Help is greatly appreciated.

So this function would be something like "get last modified date based on file path". I will need step by step instructions as I am not very familiar with VBA. Thanks!

Example:

A B
1 Q:\Folder1\File name1.xls 2/10/2012
2 X:\Folder2\File name2.xls 12/1/2011

etc
 
Last edited:

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
apinel,

See if this will get you started in the right direction:

http://www.mrexcel.com/forum/showthread.php?t=373373

Thank you for the link!
The code works fine. However it is not too efficient if you have a couple of hundred files that I need to check the last modified date. Is it possible to reference the cell instead of the actual file path, in the code? Otherwise I have to manually input the file path in the code for each file. For example, the code calls for the following line:

Set f = fso.GetFile("A:\File.ext")
Range("L3").Formula = f.DateLastModified
Range("L3").Select

Is it possible to do something like (to reference A1 in the worksheet).

Set f = fso.GetFile("A1")
Range("L3").Formula = f.DateLastModified
Range("L3").Select

I tried this but got an error message saying file not found.

Also, I have another list of files on the same workbook but on a different worksheet. Is it possible to have the same code on different worksheets? Or I guess another way of saying is it possible to write a separate macro to apply to another worksheet in the same workbook?

Help is greatly appreciated.
 
Last edited:
Upvote 0
This assumes your files are listed in column B starting in B1, change column to suit. Date file was last modified will be returned in column C:
Code:
Sub GetLastDateModified()
    '**************************************************
    'Column B  of the active sheet should contain full file paths and file names
    'with file extension info
    '**************************************************

    Dim fso, f, lRw As Long
    lRw = ActiveSheet.Range("B" & Rows.Count).End(xlUp).Row
    Set fso = CreateObject("Scripting.FileSystemObject")
    For Each c In Range("B1", "B" & lRw)
        If Not IsEmpty(c) And InStr(1, c.Value, "\") > 0 Then
            Set f = fso.GetFile(c.Value)
            c.Offset(0, 1).Formula = f.DateLastModified
        End If
    Next c
End Sub
 
Upvote 0
This assumes your files are listed in column B starting in B1, change column to suit. Date file was last modified will be returned in column C:
Code:
Sub GetLastDateModified()
    '**************************************************
    'Column B  of the active sheet should contain full file paths and file names
    'with file extension info
    '**************************************************

    Dim fso, f, lRw As Long
    lRw = ActiveSheet.Range("B" & Rows.Count).End(xlUp).Row
    Set fso = CreateObject("Scripting.FileSystemObject")
    For Each c In Range("B1", "B" & lRw)
        If Not IsEmpty(c) And InStr(1, c.Value, "\") > 0 Then
            Set f = fso.GetFile(c.Value)
            c.Offset(0, 1).Formula = f.DateLastModified
        End If
    Next c
End Sub

This works great! Thanks!
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,331
Members
452,636
Latest member
laura12345

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