LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Copy data from all the file file from a folder.




Sub GetBooks()

Folder = "C:\Temp\"
'Get each XLS file in the Folder, will return an empty string after last file
FName = Dir(Folder & "*.xls")
'loop until there are no more files to open
Do While FName < ""
'Open sleected file
Set OldBk = Workbooks.Open(Filename:=Folder & FName)
'open workbook become active so must specify original book
With ThisWorkbook
'copy sheet from open book to this book
'Require AFTER otherwise sheet goes in a new workbook
'Place Copied sheet as last sheet in workbook
OldBk.ActiveSheet.Copy _
after:=.Sheets(.Sheets.Count)
'Make sheet name the same as workbook name
ActiveSheet.Name = FName
End With
'close workbook that was opened.
'specify savechanges false so nothing is changed in opened book
'also savechanges are needed so pop-up window doesn't
'show up after every file.
OldBk.Close savechanges:=False
'get next file in search criteria
FName = Dir()
Loop

End Sub


"Heera" wrote:

Hi,

Joel your code is working fine. I would appriciate if you can explain
me what this macro is doing at each step. It will be a great help for
me next time when ever i write the macro.

Regards

Heera

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
copy data for match word from one file to another file mishak Excel Worksheet Functions 1 December 2nd 09 02:11 AM
Open and copy all workbook sheets in a folder to a master file [email protected] Excel Discussion (Misc queries) 0 November 2nd 06 04:29 PM
Capture data in one 'destination' file from varied 'source' file stored in one single folder. Smits Excel Programming 4 October 7th 06 12:35 PM
Create a copy in the same folder when a file is modified and saved Turboj Excel Discussion (Misc queries) 1 February 21st 06 04:51 AM
Copy an excel file to new created folder Myrna Rodriguez Excel Programming 2 September 9th 04 01:54 PM


All times are GMT +1. The time now is 06:52 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"