Results 1 to 3 of 3

change code from filesearch to FSO and Dir

Threaded View

  1. #1
    Registered User
    Join Date
    03-18-2010
    Location
    Alkmaar, Holland
    MS-Off Ver
    Excel 2003
    Posts
    3

    change code from filesearch to FSO and Dir

    Hello everybody.

    i did write some code in VBA reading all files with fitting a wildcard format from a given directory and all subdirectorys and place the found files and path in an excel sheet.

    I used herefore the Application.FIleSearch object.
    The problem is that this sometimes not working with Windows 7 or is not always recognizing "zip" files.

    I Googled on internet and learned that it will be better to use FileSystemObject and Dir to do the job, because FileSearch is not allways supported by the system.

    I did try to translate the code, but couldn't work it out.

    How to translate the next code in the other FSO and Dir format?

    Set bz = Application.FileSearch
    With bz
        .LookIn = FilePad
        .SearchSubFolders = True
        .Filename = wildC
        If .Execute(SortBy:=msoSortByNone, SortOrder:=msoSortOrderAscending) > 0 Then
            Sheets(Sheetnames(1)).Range("p5").Value = .FoundFiles.Count       'Plaats hoeveelheid files in P5
      
            For i = 1 To .FoundFiles.Count
                Sheets(Sheetnames(1)).Select
                Range("A" & i + offset).Value = .FoundFiles(i)         'ZET FILENAME IN KOLOM A
                plek = Testlocatie(i + offset, plek)                   'TEST OF THE FILE NAAM IN BEIDE SHEETS OVEREENKOMEN OP DEZELFDE LOCATIE
                plek = plek + 1
            Next
        End If
        Set bz = Nothing

    wereby WildC is the wildcard to search for and Filepad is the starting directory to look from including all subdirectorys?

    Any help would be preciated.
    Last edited by canedje; 03-18-2010 at 07:35 AM.

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