Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 27
Default Combine worksheets in multiple workbook in one workbook with a macro

I was provided the following macro to combine multiple workbook sheets in
one sheet however I am getting the error -"Run time error 424" Object
required on the lines below

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

I would really apprceiate if someone can guide me on what the fix of this
error might be.


---------

Please see complete macro below.



The macro below will search each folder in the Root directory and combine
all
sheets in all workbook into a single workbook. then it will save the new
book in the same directory 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


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,549
Default Combine worksheets in multiple workbook in one workbook with a macro


Untested, but may be what is needed...
newbk.SaveAs Filename:=sf.Path & "\" & sf.Name & ".xls"
--
Jim Cone
Portland, Oregon USA



"Sam Commar"
wrote in message
I was provided the following macro to combine multiple workbook sheets in
one sheet however I am getting the error -"Run time error 424" Object
required on the lines below

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

I would really apprceiate if someone can guide me on what the fix of this
error might be.
---------
Please see complete macro below.
The macro below will search each folder in the Root directory and combine
all sheets in all workbook into a single workbook. then it will save the new
book in the same directory using the parent folders name.
-snip-
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Combine worksheets in multiple workbook in one workbook with a macro

Check your other post.

Sam Commar wrote:

I was provided the following macro to combine multiple workbook sheets in
one sheet however I am getting the error -"Run time error 424" Object
required on the lines below

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

I would really apprceiate if someone can guide me on what the fix of this
error might be.

---------

Please see complete macro below.

The macro below will search each folder in the Root directory and combine
all
sheets in all workbook into a single workbook. then it will save the new
book in the same directory 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



--

Dave Peterson
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
Combine multiple workbooks into one workbook YM TEO Excel Discussion (Misc queries) 4 March 31st 09 08:17 AM
how can I combine multiple worksheets into a single workbook? don_15D Excel Discussion (Misc queries) 6 January 3rd 09 07:51 AM
Combine multiple workbooks into 1 workbook w/ multiple worksheets buffgirl71 Excel Discussion (Misc queries) 1 May 13th 06 12:28 PM
Combine multiple workbooks into 1 workbook w/ multiple worksheets buffgirl71 Excel Discussion (Misc queries) 2 May 12th 06 10:30 PM
Combine multiple workbooks into one workbook Rookie_User Excel Discussion (Misc queries) 0 January 13th 06 06:56 PM


All times are GMT +1. The time now is 12:44 PM.

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

About Us

"It's about Microsoft Excel"