I need to combine about 16 different excel files (one workbook each) into
excel file. I don't want to combine them all into one worksheet. I need to
keep them separate, but in the same workbook. They all have the same format.
Thanks in advance.
Are they all in the same folder?
If yes, then run this and select the files that should be combined:
Option Explicit
Sub testme01()
Dim myFileNames As Variant
Dim wkbk As Workbook
Dim fCtr As Long
Dim newWkbk As Workbook
myFileNames = Application.GetOpenFilename(quot;Excel Files, *.xlsquot;, _
MultiSelect:=True)
If IsArray(myFileNames) = False Then
Exit Sub
End If
Set newWkbk = Workbooks.Add(1) 'single sheet
newWkbk.Worksheets(1).Name = quot;dummynameherequot;
For fCtr = LBound(myFileNames) To UBound(myFileNames)
Set wkbk = Workbooks.Open(Filename:=myFileNames(fCtr))
wkbk.Worksheets(1).Copy _
after:=newWkbk.Worksheets(1)
wkbk.Close savechanges:=False
Next fCtr
Application.DisplayAlerts = False
newWkbk.Worksheets(quot;dummynameherequot;).Delete
Application.DisplayAlerts = True
End Sub
dbguy11 wrote:
gt;
gt; I need to combine about 16 different excel files (one workbook each) into
gt; excel file. I don't want to combine them all into one worksheet. I need to
gt; keep them separate, but in the same workbook. They all have the same format.
gt; Thanks in advance.
--
Dave Peterson
quot;dbguy11quot; gt; wrote in message
...
gt;I need to combine about 16 different excel files (one workbook each) into
gt; excel file. I don't want to combine them all into one worksheet. I need to
gt; keep them separate, but in the same workbook. They all have the same
gt; format.
gt; Thanks in advance.
Right click the tab at the bottom and you'll see options for copying the
sheet. You can make a copy that stays in the same workbook, or send the copy
to a new workbook, or...the one you want: Copy it into an existing workbook.
The workbook that receives the copy must be open at the time of the copy.
- Nov 21 Wed 2007 20:41
Combine worksheets from different excel files into one excel file
close
全站熱搜
留言列表
發表留言