Question posted 2009 · +5 upvotes
I monthly receive 100+ excel spreadsheet from wich i take a fixed range and paste in other spreadsheet to make a report.
Im trying to write a vba script to iterate my excel files and copy the range in one spreadsheet, but i havent been able to do it.
Is there an easy way to do this?
Accepted answer +6 upvotes
Here’s some VBA code that demonstrates iterating over a bunch of Excel files in a directory and opening each one:
Dim sourcePath As String
Dim curFile As String
Dim curWB As Excel.Workbook
Dim destWB As Excel.Workbook
Set destWB = ActiveWorkbook
sourcePath = "C:files"
curFile = Dir(sourcePath & "*.xls")
While curFile <> ""
Set curWB = Workbooks.Open(sourcePath & "" & curFile)
curWB.Close
curFile = Dir()
Wend
Hopefully that’ll be a good enough starting point for you to work your existing macro code.
Top excel-vba Q&A (6)
- How to clear the entire array? +58 (2010)
- How to change Format of a Cell to Text using VBA +55 (2011)
- Download attachment from Outlook and Open in Excel +43 (2012)
- Can a VBA function in Excel return a range? +36 (2009)
- 2 Dimensional array from range +34 (2013)
- Hiding an Excel worksheet with VBA +33 (2009)
excel-vba solutions on this site
.