LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 312
Default Merge multiple files into 1

Hi. I need to take several files within a signle folder, and copy every
sheet with each file and paste it as it's own sheet into a master file.

So for instance:
File 1 has 3 sheets
File 2 has 5 sheets
File 3 has 1 sheet

The master file will then have 9 sheets. Basically, move each sheet from
each file into 1 file.
I have a start to this, but it only copied sheet1 of each file in a
directory. I don't know how to make it copy every sheet:

Sub OpenAllExcelFiles()
'based on a Tom Ogilvy example
With Application.FileSearch
.NewSearch


.LookIn = "C:\Data" '<== set the directory
.SearchSubFolders = False
.Filename = "*.xls"
.MatchTextExactly = True
.FileType = msoFileTypeExcelWorkbooks
If .Execute() 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
Set wkbk = Workbooks.Open(Filename:=.FoundFiles(i))
'
wkbk.Worksheets("sheet1").Copy _
after:=ThisWorkbook.Sheets(1) 'Change sheet name
wkbk.Close
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub


 
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
how do I merge multiple csv files in one Excel file? Nedulous Excel Worksheet Functions 4 May 17th 09 04:07 PM
merge multiple worksheets from multiple excel files into oneworksheet Shamoun Ilyas Excel Discussion (Misc queries) 5 November 19th 08 09:48 PM
How do I merge multiple xls files into one file? Steve Excel Discussion (Misc queries) 5 April 26th 07 08:28 PM
How do I merge multiple xls files into one file? Gianni Excel Discussion (Misc queries) 3 June 14th 05 02:09 PM
How can I merge multiple files using SQL? mb Excel Programming 1 February 17th 04 10:06 AM


All times are GMT +1. The time now is 11:14 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"