Data extraction with Excel

calendar_today Asked Jul 24, 2009
thumb_up 6 upvotes
history Updated April 16, 2026

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)

+6 upvotes ranks this answer #114 out of 136 excel-vba solutions on this site .