+ Reply to Thread
Results 1 to 3 of 3

Finding File Time

Hybrid View

  1. #1
    Registered User
    Join Date
    11-18-2011
    Location
    Dorset
    MS-Off Ver
    Excel 365
    Posts
    37

    Finding File Time

    If I have, say, in a Cell the formula =Cell(FileName",A1), that generates the name of the curreent file.

    Or I might have, in a Cell, a "Value" such as
    ="C:\MyFolder\MyFile.TXT"

    How can I use this value to find the "Date / Time " stamp?

    Yes, I know there are several "styles" of these -
    Created, Modified, Accessed, archived, completed, last saved, received, released, sent, taken, deleted, any more ?
    so I also need to be able to specify which style.

    I haven't managed to find a "built-in" function - is there one ?

    So - if not - some ideas, please, for a VBA Function, so that I can use the formula
    = FileTime ( B3, myStyle )

    And of course I would then want to modify that for FileSize, FileShortName and FileAttr ;-)
    Last edited by RobinClay; 08-15-2019 at 02:13 PM.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,731

    Re: Finding File Time

    Here is a VBA that you can modify for your particular objects you wish to find. It should give you an idea of a possible direction to pursue if I am understanding your request.

    Sub ListAllFile()
    
        Dim objFSO As Object
        Dim objFolder As Object
        Dim objFile As Object
        Dim ws As Worksheet
        Dim sPath As String
        Dim lrA As Long
        Dim lrB As Long
    
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        Set ws = Worksheets.Add
    
        'Get the folder object associated with the directory
        sPath = InputBox("What is the full Path to Search?")
        Set objFolder = objFSO.GetFolder(sPath)
        ws.Cells(1, 1).Value = "The files found in " & objFolder.Name & " are:"
        ws.Cells(1, 2).Value = "The files found have modified dates:"
        ws.Cells(1, 3).Value = "The file Size is:"
    
        'Loop through the Files collection
        For Each objFile In objFolder.Files
        'If objFile.Name Like "*.pdf" Then
            lrA = Range("A" & Rows.Count).End(xlUp).Row
            lrB = Range("B" & Rows.Count).End(xlUp).Row
            ws.Range("A" & lrA + 1).Value = objFile.Name
            ws.Range("B" & lrB + 1).Value = objFile.DateLastModified
            ws.Range("C" & lrB + 1).Value = objFile.Size
        'End If
        Next
        'ws.Cells(2, 1).Delete
        'Clean up!
        Set objFolder = Nothing
        Set objFile = Nothing
        Set objFSO = Nothing
    
    End Sub
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: Finding File Time

    You can access following 3 datetime using Scripting.FileSystemObject.
    DateCreated, DateLastModified, DateLastAccessed

    Archived is just an attribute on the file object and note datetime. Assuming it was archived, then last modified should be the archived date.
    Other datetime / attributes you listed, does not exist in file object record.

    Ex:
    Public Function GetFileDates(strFile As String, dType As Integer)
    Dim oFS As Object
    Set oFS = CreateObject("Scripting.FileSystemObject")
    
    Select Case dType
        Case Is = 1
            temp = oFS.GetFile(strFile).DateCreated
        Case Is = 2
            temp = oFS.GetFile(strFile).DateLastModified
        Case Is = 3
            temp = oFS.GetFile(strFile).DateLastAccessed
        Case Else
            temp = "Invalid dType, select 1 to 3"
    End Select
    
    GetFileDates = temp
        
    End Function
    "Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something."
    ― Robert A. Heinlein

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 10
    Last Post: 03-24-2019, 11:57 AM
  2. Finding a file in folder based on first 2 numbers in file name
    By georgemaka in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-12-2015, 06:42 PM
  3. [SOLVED] Time in Time format and text foramt - Finding the Hours difference
    By thilag in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-19-2013, 07:14 AM
  4. [SOLVED] Finding a file in sub folders and taking you to the location of searched file
    By subbby in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 10-09-2013, 01:25 PM
  5. Finding a line in a text file, offset x rows, and copy everything else in the file
    By new.vbacoder in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-27-2010, 12:53 PM
  6. Finding data on a dump file, populating rows in a summary file
    By SBells in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-21-2008, 08:29 AM
  7. Finding File Creation Time
    By bassoonboy in forum Excel General
    Replies: 0
    Last Post: 07-17-2006, 10:44 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1