ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Looping through all workbooks (https://www.excelbanter.com/excel-programming/272935-re-looping-through-all-workbooks.html)

Mervyn Thomas[_3_]

Looping through all workbooks
 
Many thanks - about to test

Mervyn

"Patrick Molloy" wrote in message
...
Sub MultiCopy()
dim wbMaster as Workbook, wsMaster as worksheet
dim wbTemp as Workbook
dim wsTemp as worksheet
dim fn as string
dim rw as long

' set the initial file using
fn = DIR("C:\Root\Subfolders\*.xls")
' fn will hold the first file matching *.xls
if fn ="" then exit sub

set wbMaster = _
Workbooks.Open("C:\Pathtomaster\Master.xls")
set wsMaster = wbMaster.Activesheet

do until fn =""
set wbTemp = Workbooks.Open(fn)
set wsTemp = wbTempActivesheet
' copy data
' your code eg
' next free row in master
rw = wsMaster.Range("A1").End(xlDown).Row + 1
' say 2 x 10
with wsMaster
.cells(.cells(rw,1),.cells(rw+1,10)).Value = _
wsTemp.Range("A1:B10").Value
end with

' close temp book
wbTemp.Close false ' false means don't save
set wsTemp = nothing
set wbTemp = Nothing

' get the next file
fn = DIR
' fn will be empty if there are no more files
loop

msgbox "Done"

End Sub

HTH
Patrick Molloy
Microsoft Excel MVP



-----Original Message-----
Can someone give me a start to the code to open all the

workbooks in turn
that are in a specific directory and then to copy

specific cells to a
masterfile in a different directory? thanks in advance


.





All times are GMT +1. The time now is 07:04 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com