Got any Excel/VBA Questions? Excel Help.
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. https://buyiglikesfast.com/buy-instagram-likes/
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
Microsoft ® and Microsoft Excel ® are registered trademarks of Microsoft Corporation. OzGrid is in no way associated with Microsoft
See also:
Auto-Run-Macros |
Excel AutoFilters in VBA using Dates |
Criteria for VBA filters |
Excel VBA AutoFilters |
Free Training Course: Lesson 1 - Excel Fundamentals
See also: Index to Excel VBA Code; Index to Excel Freebies; Lesson 1 - Excel Fundamentals; Index to how to… providing a range of solutions
Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.