+ Reply to Thread
Results 1 to 4 of 4

Excel File Directory - List NEW Files only

Hybrid View

lilanngel Excel File Directory - List... 01-09-2013, 02:46 PM
OllieB Re: Excel File Directory -... 01-09-2013, 02:51 PM
OllieB Re: Excel File Directory -... 01-09-2013, 02:52 PM
TMS Re: Excel File Directory -... 01-09-2013, 03:54 PM
  1. #1
    Registered User
    Join Date
    02-23-2010
    Location
    California, USA
    MS-Off Ver
    Excel 2007
    Posts
    14

    Excel File Directory - List NEW Files only

    I've found lots of Excel VBA code for creating a file directory in Excel, and they have been absolutely wonderful.

    I've created a file directory using file paths and file names (and have about 20 files in there). However, since it's a shared folder, people will be adding new files to it all the time. If I click the "Grab Files" button again, I end up duplicating the original 20 files, and getting additional (new) files.

    Is there a way to setup this directory to include ONLY the new files by "updating" it? Perhaps it can check which files are already listed in the file directory - and add only the new ones to the list? Is this possible? Any help would be great!! Thank you!

    Sub GrabFiles()
        Dim strPathFile As String
        Dim xDirect$, xFname$, InitialFoldr$, xLocation
        Application.ScreenUpdating = False
        Range("C1").Formula = "Updated on:"
        Range("D1").Formula = "=Today()"
        Range("D1").Copy
        Range("D1").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Application.CutCopyMode = False
         
        InitialFoldr$ = ""
       With Application.FileDialog(msoFileDialogFolderPicker)
            .InitialFileName = Application.DefaultFilePath & "\"
            .Title = "Please select the TARA folder"
            .InitialFileName = InitialFoldr$
            .Show
        If .SelectedItems.Count <> 0 Then
                xDirect$ = .SelectedItems(1)
        ListFilesInFolder xDirect$, True
        End If
        End With
    End Sub
    
    Sub ListFilesInFolder(SourceFolderName As String, IncludeSubfolders As Boolean)
    Dim FSO As Scripting.FileSystemObject
    Dim SourceFolder As Scripting.Folder, SubFolder As Scripting.Folder, SubFolders As Scripting.Folders
    Dim FileItem As Scripting.File
    Dim r As Long
        Set FSO = New Scripting.FileSystemObject
        Set SourceFolder = FSO.GetFolder(SourceFolderName)
        r = Range("A65536").End(xlUp).Row + 1
        For Each FileItem In SourceFolder.Files
            Cells(r, 1).Formula = FileItem.Path
            'Space for Link
            Cells(r, 3).Formula = FileItem.Name
            'Space for Description
            r = r + 1
        Next FileItem
        If IncludeSubfolders Then
            For Each SubFolder In SourceFolder.SubFolders
                ListFilesInFolder SubFolder.Path, True
            Next SubFolder
        End If
            Range("A2").Select
        Set FileItem = Nothing
        Set SourceFolder = Nothing
        Set FSO = Nothing
        ActiveWorkbook.Saved = True
        Range("F3:F1000").EntireRow.AutoFit
        LastRow = Range("D" & Rows.Count).End(xlUp).Row + 1
        Sheets("Grab Files").Range("D" & LastRow).Select
        ActiveWindow.ScrollRow = Selection.Row
    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: Excel File Directory - List NEW Files only

    Please have a look at a solution I wrote for a similar request today

    http://www.excelforum.com/excel-prog...-in-order.html

    This solution uses a dictionary object to keep track of the file already in the register
    If you like my contribution click the star icon!

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

    Re: Excel File Directory - List NEW Files only

    Please have a look at a solution I wrote for a similar request today

    http://www.excelforum.com/excel-prog...-in-order.html

    This solution uses a dictionary object to keep track of the file already in the register

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,164

    Re: Excel File Directory - List NEW Files only

    Perhaps a naive question, but why don't you just clear the output sheet at the start of the macro.

    Seems a lot of effort to go to add new files ... which implies checking each file against the existing list and, if it doesn't exist, add it. If it does, ignore it. You still have to loop through the entire folder/sub-folder structure.

    Just a thought.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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