ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   How to Use DateLastModified Property in VBA? (https://www.excelbanter.com/excel-discussion-misc-queries/125766-how-use-datelastmodified-property-vba.html)

HROBERTSON

How to Use DateLastModified Property in VBA?
 
How can I use the DateLastModified property in VBA to pull into my current
open spreadsheet, the last modified date of another file (one that is
closed.) I want, if possible, to add it to a cell.

As always, your help is greatly appreciated.

Thank You!

ExcelBanter AI

Answer: How to Use DateLastModified Property in VBA?
 
Sure, I'd be happy to help you with that!

To use the DateLastModified property in VBA, you can follow these steps:
  1. Open the VBA editor in Excel by pressing Alt + F11.
  2. In the editor, go to Insert Module to create a new module.
  3. In the new module, you can use the following code to get the last modified date of a file:

    Formula:

    Function GetLastModified(filePath As String) As Date
        GetLastModified 
    FileDateTime(filePath)
    End Function 

    This code defines a function called GetLastModified that takes a file path as an argument and returns the last modified date of the file.
  4. To use this function in your current open spreadsheet, you can add a formula to a cell that references the function and passes the file path as an argument. For example, if the file you want to get the last modified date of is "C:\Users\JohnDoe\Documents\MyFile.xlsx", you can add the following formula to a cell:

    =GetLastModified("C:\Users\JohnDoe\Documents\MyFil e.xlsx")

    This formula will return the last modified date of the file.

Let me know if you have any questions or if there's anything else I can do for you.

Gary''s Student

How to Use DateLastModified Property in VBA?
 
Function lastsaved() As Double
lastsaved = ActiveWorkbook.BuiltinDocumentProperties(12)
End Function

Gives the date/time last saved

For the properites of closed files, see:

http://www.cpearson.com/excel/docprop.htm
Document Properties Of Closed Files DSO Version 2.0
--
Gary's Student


"HROBERTSON" wrote:

How can I use the DateLastModified property in VBA to pull into my current
open spreadsheet, the last modified date of another file (one that is
closed.) I want, if possible, to add it to a cell.

As always, your help is greatly appreciated.

Thank You!


Gord Dibben

How to Use DateLastModified Property in VBA?
 
Run first macro to get second macro to return the date.

Sub anotherfiledate()
ShowFileAccessInfo ("closedfile.xls")
End Sub

Sub ShowFileAccessInfo(filespec)
Dim fs, f, s
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(filespec)
s = UCase(filespec) ' & vbCrLf
Range("K3").Value = s & " Last Modified: " & f.DateLastModified
End Sub


Gord Dibben MS Excel MVP

On Thu, 11 Jan 2007 11:11:00 -0800, HROBERTSON
wrote:

How can I use the DateLastModified property in VBA to pull into my current
open spreadsheet, the last modified date of another file (one that is
closed.) I want, if possible, to add it to a cell.

As always, your help is greatly appreciated.

Thank You!




All times are GMT +1. The time now is 11:30 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com