Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Combine files as tabs in a single Workbook

I have 3 Excel files in a folder. I wanted to setup some kind of macro or
programming to combine the three files as three tabs in a single file. Could
someone kindly assist me on this.
2 of the excel files have 2 tabs each and one file has 1 tab. So when they
are combined it makes one file with 5 tabs.


In effect I will have 20 folder each with 3 files -structure will be the
same that is 2 files with 2 tabs and 1 file with one tab and they are to be
made into one file with tabs.



Thanks so much for your help

Sam Commar

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Combine files as tabs in a single Workbook

The macro below will seach each folder in the Root directroy and combine all
sheets in all workbook into a single workbook. then it will save the new
book in the same directroy using the parent folders name.


Sub Combinebooks()

Root = "c:\Temp"


Set fso = CreateObject _
("Scripting.FileSystemObject")

Set folder = _
fso.GetFolder(Root)

For Each sf In folder.subfolders
First = True
FName = Dir(sf & "\*.xls")
Do While FName < ""
Set bk = Workbooks.Open(Filename:=sf & "\" & FName)
For Each sht In bk.Sheets
If First = True Then
sht.Copy
Set newbk = ActiveWorkbook
First = False
Else
With newbk
sht.Copy _
after:=.Sheets(.Sheets.Count)
End With
End If
Next sht
bk.Close savechanges:=False
FName = Dir()
Loop
newbk.SaveAs Filename:=sf & "\" & _
sf.Name & ".xls"
newbk.Close
Next sf

End Sub



"Sam Commar" wrote:

I have 3 Excel files in a folder. I wanted to setup some kind of macro or
programming to combine the three files as three tabs in a single file. Could
someone kindly assist me on this.
2 of the excel files have 2 tabs each and one file has 1 tab. So when they
are combined it makes one file with 5 tabs.


In effect I will have 20 folder each with 3 files -structure will be the
same that is 2 files with 2 tabs and 1 file with one tab and they are to be
made into one file with tabs.



Thanks so much for your help

Sam Commar

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Combine files as tabs in a single Workbook

Joel

Thanks so much . I really appreciate it. Ill test it right now.

"joel" wrote in message
...
The macro below will seach each folder in the Root directroy and combine
all
sheets in all workbook into a single workbook. then it will save the new
book in the same directroy using the parent folders name.


Sub Combinebooks()

Root = "c:\Temp"


Set fso = CreateObject _
("Scripting.FileSystemObject")

Set folder = _
fso.GetFolder(Root)

For Each sf In folder.subfolders
First = True
FName = Dir(sf & "\*.xls")
Do While FName < ""
Set bk = Workbooks.Open(Filename:=sf & "\" & FName)
For Each sht In bk.Sheets
If First = True Then
sht.Copy
Set newbk = ActiveWorkbook
First = False
Else
With newbk
sht.Copy _
after:=.Sheets(.Sheets.Count)
End With
End If
Next sht
bk.Close savechanges:=False
FName = Dir()
Loop
newbk.SaveAs Filename:=sf & "\" & _
sf.Name & ".xls"
newbk.Close
Next sf

End Sub



"Sam Commar" wrote:

I have 3 Excel files in a folder. I wanted to setup some kind of macro or
programming to combine the three files as three tabs in a single file.
Could
someone kindly assist me on this.
2 of the excel files have 2 tabs each and one file has 1 tab. So when
they
are combined it makes one file with 5 tabs.


In effect I will have 20 folder each with 3 files -structure will be the
same that is 2 files with 2 tabs and 1 file with one tab and they are to
be
made into one file with tabs.



Thanks so much for your help

Sam Commar

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Combine files as tabs in a single Workbook

Joel

When I run it it errors out on the item below

newbk.SaveAs Filename:=sf & "\" & _
sf.Name & ".xls"

"Sam Commar" wrote in message
...
Joel

Thanks so much . I really appreciate it. Ill test it right now.

"joel" wrote in message
...
The macro below will seach each folder in the Root directroy and combine
all
sheets in all workbook into a single workbook. then it will save the new
book in the same directroy using the parent folders name.


Sub Combinebooks()

Root = "c:\Temp"


Set fso = CreateObject _
("Scripting.FileSystemObject")

Set folder = _
fso.GetFolder(Root)

For Each sf In folder.subfolders
First = True
FName = Dir(sf & "\*.xls")
Do While FName < ""
Set bk = Workbooks.Open(Filename:=sf & "\" & FName)
For Each sht In bk.Sheets
If First = True Then
sht.Copy
Set newbk = ActiveWorkbook
First = False
Else
With newbk
sht.Copy _
after:=.Sheets(.Sheets.Count)
End With
End If
Next sht
bk.Close savechanges:=False
FName = Dir()
Loop
newbk.SaveAs Filename:=sf & "\" & _
sf.Name & ".xls"
newbk.Close
Next sf

End Sub



"Sam Commar" wrote:

I have 3 Excel files in a folder. I wanted to setup some kind of macro
or
programming to combine the three files as three tabs in a single file.
Could
someone kindly assist me on this.
2 of the excel files have 2 tabs each and one file has 1 tab. So when
they
are combined it makes one file with 5 tabs.


In effect I will have 20 folder each with 3 files -structure will be the
same that is 2 files with 2 tabs and 1 file with one tab and they are to
be
made into one file with tabs.



Thanks so much for your help

Sam Commar

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Combine files as tabs in a single Workbook

Sorry the error it gives is

Run time error '424'
Object required

"Sam Commar" wrote in message
...
Joel

When I run it it errors out on the item below

newbk.SaveAs Filename:=sf & "\" & _
sf.Name & ".xls"

"Sam Commar" wrote in message
...
Joel

Thanks so much . I really appreciate it. Ill test it right now.

"joel" wrote in message
...
The macro below will seach each folder in the Root directroy and combine
all
sheets in all workbook into a single workbook. then it will save the
new
book in the same directroy using the parent folders name.


Sub Combinebooks()

Root = "c:\Temp"


Set fso = CreateObject _
("Scripting.FileSystemObject")

Set folder = _
fso.GetFolder(Root)

For Each sf In folder.subfolders
First = True
FName = Dir(sf & "\*.xls")
Do While FName < ""
Set bk = Workbooks.Open(Filename:=sf & "\" & FName)
For Each sht In bk.Sheets
If First = True Then
sht.Copy
Set newbk = ActiveWorkbook
First = False
Else
With newbk
sht.Copy _
after:=.Sheets(.Sheets.Count)
End With
End If
Next sht
bk.Close savechanges:=False
FName = Dir()
Loop
newbk.SaveAs Filename:=sf & "\" & _
sf.Name & ".xls"
newbk.Close
Next sf

End Sub



"Sam Commar" wrote:

I have 3 Excel files in a folder. I wanted to setup some kind of macro
or
programming to combine the three files as three tabs in a single file.
Could
someone kindly assist me on this.
2 of the excel files have 2 tabs each and one file has 1 tab. So when
they
are combined it makes one file with 5 tabs.


In effect I will have 20 folder each with 3 files -structure will be
the
same that is 2 files with 2 tabs and 1 file with one tab and they are
to be
made into one file with tabs.



Thanks so much for your help

Sam Commar



Reply
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 to set up single Header/Footer for all tabs in Excel Workbook. headers & footers repeated Excel Worksheet Functions 2 July 17th 09 12:18 AM
how can I combine multiple worksheets into a single workbook? don_15D Excel Discussion (Misc queries) 6 January 3rd 09 07:51 AM
Trying to write macro to combine data in multiple tabs into a single tab. [email protected] Excel Programming 3 June 15th 07 04:13 PM
merging single worksheet files into a single workbook DDK Excel Discussion (Misc queries) 1 December 5th 06 05:25 PM
Select sheet tabs in workbook & save to separate workbook files stratocaster Excel Worksheet Functions 2 March 1st 06 03:35 PM


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