SITE HELPFUL ?

Excel is what we do best
ALL YOUR EXCEL NEEDS
FREE Excel STUFF
Excel Newsletter
Advanced Search Search Excel Content
PRODUCTS
Development
Contact Us
Learn how to create Excel dashboards.

Excel 2007 Alternative To File Search

TRY OUT: Smart-VBA | Code-VBA | Analyzer-XL | Downloader-XL | Trader-XL| More Free Downloads.. Best Value: Finance Templates Bundle

Loop Through a Folder of Excel 2007 Workbooks

Current Special! Complete Excel Excel Training Course for Excel 97 - Excel 2003, only $145.00. $59.95 Instant Buy/Download, 30 Day Money Back Guarantee & Free Excel Help for LIFE!

Got any Excel Questions? Excel Help .

See Also: Loop Through Workbooks Pre 2007 | Loop Through Worksheets | Create a Hyperlinked List of Excel Workbook

Loop Through a Folder of Excel Workbooks

With the use of Excel 2007 VBA Macro code we can loop through a Folder on ones Hard-drive and work on all Excel Workbooks within it. The code below can be used on any version of Excel. The only changes needed are to the file paths used.  In this example code, I copy all Worksheets called "Template" into a new Workbook, then name the sheet using A1 of the same sheet.

Sub CopySameSheetFrmWbs()
Dim wbOpen As Workbook
Dim wbNew As Workbook
'Change Path
Const strPath As String = "C:\Excel\"
Dim strExtension As String

'Comment out the 3 lines below to debug
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
On Error Resume Next

    ChDir strPath
'Change extension
strExtension = Dir("*.xls")
    
    Set wbNew = Workbooks.Add
'Change Path, Name and File Format
wbNew.SaveAs Filename:="C:\Excel\TemplateCollation", FileFormat:=xlWorkbookNormal
    
        Do While strExtension <> ""
            Set wbOpen = Workbooks.Open(strPath & strExtension)
         
            With wbOpen
                .Sheets("Template").Copy After:=wbNew.Sheets(wbNew.Sheets.Count)
                wbNew.Sheets(wbNew.Sheets.Count).Name = wbNew.Sheets(wbNew.Sheets.Count).Cells(1, 1)
                .Close SaveChanges:=False
            End With
            
            strExtension = Dir
        Loop
        
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
On Error GoTo 0
End Sub

Excel Dashboard Reports & Excel Dashboard Charts 50% Off

Become an ExcelUser Affiliate & Earn Money

Special! Free Choice of Complete Excel Training Course OR Excel Add-ins Collection on all purchases totaling over $64.00. ALL purchases totaling over $150.00 gets you BOTH! Purchases MUST be made via this site. Send payment proof to [email protected] 31 days after purchase date.


Instant Download and Money Back Guarantee on Most Software

Excel Trader Package Technical Analysis in Excel With $139.00 of FREE software!

Add to Google Search Tips FREE Excel Help

Microsoft � and Microsoft Excel � are registered trademarks of Microsoft Corporation. OzGrid is in no way associated with Microsoft

GIVE YOURSELF OR YOUR COMPANY 24/7 MICROSOFT EXCEL SUPPORT & QUESTIONS