+ Reply to Thread
Results 1 to 2 of 2

VBA Macro to Loop and Merge Files in Several Directories

  1. #1
    Registered User
    Join Date
    11-27-2012
    Location
    France
    MS-Off Ver
    Excel 2007
    Posts
    65

    VBA Macro to Loop and Merge Files in Several Directories

    Hi,

    I have this macro which merges excel file data contained in one particular directory, its working fine there! However, I have several of these directories and I want this macro to perform the similar operation in all directories. So, normally I run this code folder by folder, now I want it to run in one folder and move automatically to next folder and do the same operation (merge all the excel files present there! How will it be possible? Can you suggest me better ways? I found this code in the page of Ron de Bruin: http://www.rondebruin.nl/tips.htm

    The code is here:
    Please Login or Register  to view this content.
    It'd be very very very helpful if you can get me a solution. Thanks!

    Sanjeev

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: VBA Macro to Loop and Merge Files in Several Directories

    You can use the FileSystem Object

    Sub test()

    Dim fso As New Scripting.FileSystemObject
    Dim fl As File
    Dim fld As Folder
    Dim fld_main As Folder

    Set fld_main = fso.GetFolder("c:\")

    For Each fld In fld_main.SubFolders

    For Each fl In fld.Files

    If InStr(1, fl.Name, ".xls") > 0 Then

    ' Import

    End If

    Next fl

    Next fld

    End Sub

+ 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