Last Modified File Name into Specific Cell
Results 1 to 4 of 4

Thread: Last Modified File Name into Specific Cell
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Apr 2019
    Posts
    11
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile Last Modified File Name into Specific Cell

    I have a project going on at the moment whereby I need to go into multiple folders and pick up some files to convert to PDF. That part I am fine with but to get the file names to start I want a Macro to run and get the name of the latest modified file and put that name into a specific cell.

    An example would be go to "C:\Documents" and look at the last modified date of each file and place the latest one into cell "D3".

    I have searched high and low but cant seem to get anything that does this.

    Is there anyone who could help me out?

  2. #2
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    5,322
    Post Thanks / Like
    Mentioned
    51 Post(s)
    Tagged
    14 Thread(s)

    Default Re: Last Modified File Name into Specific Cell

    Try this.
    The result will be in cells D3 and E3

    Code:
    Sub Last_Modified_File()
        Dim wPath As String, wName As String
        Dim wFile As Object, wFso As Object, wMax As Variant
        
        wPath = "C:\Documents\"
        Set wFso = CreateObject("Scripting.FileSystemObject")
        For Each wFile In wFso.GetFolder(wPath).files
            If wFile.DateLastModified > wMax Then
                wMax = wFile.DateLastModified
                wName = wFile.Name
            End If
        Next
        Range("D3").Value = wName
        Range("E3").Value = wMax
    End Sub
    Regards Dante Amor

  3. #3
    New Member
    Join Date
    Apr 2019
    Posts
    11
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Last Modified File Name into Specific Cell

    Thank you that has worked

  4. #4
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    5,322
    Post Thanks / Like
    Mentioned
    51 Post(s)
    Tagged
    14 Thread(s)

    Default Re: Last Modified File Name into Specific Cell

    Quote Originally Posted by Cagey93 View Post
    Thank you that has worked
    I'm glad to help you. Thanks for the feedback.
    Regards Dante Amor

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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