Consulting

Results 1 to 6 of 6

Thread: Extract files name from a folder

  1. #1
    VBAX Newbie
    Joined
    Nov 2006
    Posts
    2
    Location

    Extract files name from a folder

    Hi,
    I have a folder (c:\codes...)that contains files .pdf.
    I would like to know, if is possible, extract a list of them and copy this list in a excel column.
    If yes ... when I'll add a file in (c:\codes) is possible to update automatically the excel coloum?

    Thank you in advanced and best regards,

    Milluz70

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by milluz70
    I have a folder (c:\codes...)that contains files .pdf.
    I would like to know, if is possible, extract a list of them and copy this list in a excel column.
    [vba]

    Sub ProcessFiles()
    Dim FSO As Object
    Dim i As Long
    Dim sFolder As String
    Dim Folder As Object
    Dim file As Object
    Dim Files As Object
    Dim cnt As Long

    Set FSO = CreateObject("Scripting.FileSystemObject")

    sFolder = "C:\MyTest"
    If sFolder <> "" Then
    Set Folder = FSO.GetFolder(sFolder)

    Set Files = Folder.Files
    cnt = 1
    For Each file In Files
    If file.Type = "Adobe Acrobat Document" Then
    Cells(cnt, "A").Value = file.Name
    cnt = cnt + 1
    End If
    Next file

    End If ' sFolder <> ""

    End Sub
    [/vba]

    I
    Quote Originally Posted by milluz70
    f yes ... when I'll add a file in (c:\codes) is possible to update automatically the excel coloum?
    Not really, unless you continually check the directory and re-build the list.

  3. #3
    VBAX Newbie
    Joined
    Nov 2006
    Posts
    2
    Location
    Great xld.
    It is perfect for my need.

    Thank you !!!

    milluz70

  4. #4

    Other option

    Hi, i use this code for show directory contents.
    Sorry, but I?m brazilian and my English is poor...


    [vba]
    Private Sub Workbook_Open()
    Set pa = Application.FileSearch
    With pa
    .LookIn = "C:\Codes"
    .SearchSubFolders = True
    .Filename = *.pdf

    If .Execute(SortBy:=msoSortByFileName) = 1 Then
    MsgBox "Found " & .FoundFiles.Count & " file."
    For i = 1 To .FoundFiles.Count
    Plan1.Range("B500").End(xlUp).Offset(1, 0).Value = .FoundFiles(i)
    Next i

    ElseIf .Execute(SortBy:=msoSortByFileName) > 1 Then
    MsgBox "Found " & .FoundFiles.Count & " files."
    For i = 1 To .FoundFiles.Count
    Plan1.Range("B500").End(xlUp).Offset(1, 0).Value = .FoundFiles(i)
    Next i

    Else
    MsgBox "No Found Files."
    End If
    End With
    End Sub
    [/vba]
    Last edited by mdmackillop; 11-06-2006 at 05:08 AM. Reason: VBA Tags added
    <% Marlon XL-BR %>

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Marlon,

    FYI

    If you precede you code with

    vba

    within square brackets (couldn't type them else it will treat this as VBA :-), and then

    [/vba]

    afterwards, it is much more readable.

    And FileSearch has been dropped from Excel 2007.

  6. #6

    Thanks

    Ok xld, thanks.
    <% Marlon XL-BR %>

Posting Permissions

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