Consulting

Results 1 to 3 of 3

Thread: Macro that compares directory contents to...

  1. #1
    VBAX Newbie
    Joined
    Jun 2011
    Posts
    2
    Location

    Macro that compares directory contents to...

    First, here is the current macro Im using in excel

    [VBA]Sub fileInfo()
    Dim fso As Scripting.FileSystemObject
    Dim folder As Scripting.folder
    Dim file As Scripting.file
    Dim rngEntry As Range
    Set rngEntry = Range("a1")
    Set fso = New FileSystemObject
    Set folder = fso.GetFolder("H:\DCDM\UL1")
    For Each file In folder.Files
    If LCase(Right(file.Name, 4)) = ".pdf" Then
    rngEntry = file.Name
    rngEntry.Offset(0, 1) = file.Size
    rngEntry.Offset(0, 2) = file.DateCreated
    Set rngEntry = rngEntry.Offset(1)
    End If
    Next file
    End Sub[/VBA]


    All it does at this point is list all of the contents from a directory and inserts the filenames in column 1. What Id like it to do is compare the data in column 1, search the directory, and insert all the filenames that dont currently appear on the list starting at the cell right below the last record. How can I do this? Your help is greatly appreciated!

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    [VBA]Rem Needs Reference: MicroSoft Script Runtime, scrrun.dll
    Rem Instructions: http://support.microsoft.com/default...b;en-us;186118
    Sub fileInfo()
    Dim fso As Scripting.FileSystemObject
    Dim folder As Scripting.folder
    Dim file As Scripting.file
    Dim rngEntry As Range

    Set rngEntry = Range("A" & Rows.Count).End(xlUp)
    Set fso = New FileSystemObject
    'Set folder = fso.GetFolder("H:\DCDM\UL1")
    Set folder = fso.GetFolder("X:\pdf")
    For Each file In folder.Files
    'If file.type="Adobe Acrobat Document" then
    If LCase(Right(file.Name, 4)) = ".pdf" Then
    If Not FindInRange(file.Name, Range("A1", Range("A" & Rows.Count).End(xlUp))) Then
    rngEntry = file.Name
    rngEntry.Offset(0, 1) = file.Size
    rngEntry.Offset(0, 2) = file.DateCreated
    Set rngEntry = rngEntry.Offset(1)
    End If
    End If
    Next file

    Set file = Nothing
    Set folder = Nothing
    Set fso = Nothing
    End Sub

    Function FindInRange(var As Variant, aRange As Range, Optional caseSensitve As Boolean = False) As Boolean
    If caseSensitve Then
    If Not aRange.Find(var, LookAt:=xlWhole, MatchCase:=True) Is Nothing Then FindInRange = True
    Else
    If Not aRange.Find(var, LookAt:=xlWhole) Is Nothing Then FindInRange = True
    End If
    End Function[/VBA]

  3. #3
    VBAX Newbie
    Joined
    Jun 2011
    Posts
    2
    Location
    Thanks. Ill try it out

Posting Permissions

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