+ Reply to Thread
Results 1 to 9 of 9

VBA to list only new files in folder or in order

  1. #1
    Registered User
    Join Date
    09-07-2012
    Location
    belfast
    MS-Off Ver
    Excel 2010
    Posts
    4

    VBA to list only new files in folder or in order

    Hi
    I've been tinkering about with VBA for a while now but have come up stuck.

    I have a list of files in a folder, on a excel spreadsheet I keep a register that I update every wednesday.

    I have an update buton on the register that works fine, however the problem is that the files appear in the register in no set order, and often I get duplicate files in the register.

    I have attached the VBA code I'm using below. Ideally I would like some help to set the files to appear by date or a code that adds new files only?

    Any help would be appreciated, thanks in advance

    Public Sub List_Files_In_Directory()


    Dim List_Files_In_Directory(10000, 1)
    Dim One_File_List As String
    Dim Number_Of_Files_In_Directory As Long

    One_File_List = Dir$("V:\E-PSS\" + "*.*")
    Do While One_File_List <> ""
    List_Files_In_Directory(Number_Of_Files_In_Directory, 0) = One_File_List
    One_File_List = Dir$
    Number_Of_Files_In_Directory = Number_Of_Files_In_Directory + 1
    Loop

    Number_Of_Files_In_Directory = 0
    While List_Files_In_Directory(Number_Of_Files_In_Directory, 0) <> tom
    Range("A5").Offset(Number_Of_Files_In_Directory, 0).Value = List_Files_In_Directory(Number_Of_Files_In_Directory, 0)
    Number_Of_Files_In_Directory = Number_Of_Files_In_Directory + 1
    Wend

    End Sub

  2. #2
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: VBA to list only new files in folder or in order

    Try this

    Please Login or Register  to view this content.
    If you like my contribution click the star icon!

  3. #3
    Registered User
    Join Date
    09-07-2012
    Location
    belfast
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: VBA to list only new files in folder or in order

    Magic!

    Works a treat thanks!

    Any chance you'd know a way to automatically hyperlink to the files after updating as well?

  4. #4
    Registered User
    Join Date
    09-07-2012
    Location
    belfast
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: VBA to list only new files in folder or in order

    Magic!

    Works a treat thanks!

    Any chance you'd know a way to automatically hyperlink to the files after updating as well?

  5. #5
    Registered User
    Join Date
    09-07-2012
    Location
    belfast
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: VBA to list only new files in folder or in order

    Magic!

    Works a treat! Thanks v much

    Any chance you'd also know how i could automatically hyperlink to each each file as i update to?


    Cheers

  6. #6
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: VBA to list only new files in folder or in order

    Sure can. the below code will add the hyperlink in column B (change if you will). It will also add a hyperlink for the file names already mentioned in your register but where there is no link yet in the B column. Hope this helps you

    Please Login or Register  to view this content.

  7. #7
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: VBA to list only new files in folder or in order

    Acowan, happy with this?

  8. #8
    Registered User
    Join Date
    06-24-2021
    Location
    NY
    MS-Off Ver
    365
    Posts
    1

    Re: VBA to list only new files in folder or in order

    any way to have this go through subfolders as well?

  9. #9
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: VBA to list only new files in folder or in order

    Quote Originally Posted by eanels02 View Post
    any way to have this go through subfolders as well?
    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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