|
-
Jun 16th, 2005, 02:54 AM
#1
Thread Starter
Lively Member
EXCEL combining workbooks ?
Can someone plz help me with this problem.
assume first of all that i open excel with a blank workbook (ie book1.)
my next step is to open (say?) three other workbooks. so,at this stage i have 4 open (shown in the window menu option after clicking it)
what i literally want to do is to run vba code once so that it iterates through the workbook collection (not including personal.xls if present) moving each of the 2nd, 3rd and 4th workbooks active sheet to book1.
thanks in advance
Gaz
-
Jun 16th, 2005, 03:08 AM
#2
Re: EXCEL combining workbooks ?
should be easy to do
workbooks.open filename
to open each file, then you have to choose which sheet you want to move (or copy?)
select the range within the sheet and put its copy its vaues to a loctation on the correct sheet in book1, close that work book and do the same again for the next ones
how do you know which sheet you want to move data from? all the data?
how do you know where you want to position the data in book1?
pete
-
Jun 16th, 2005, 09:06 AM
#3
Frenzied Member
Re: EXCEL combining workbooks ?
Gaz:
===
This might give you something to play with. I threw it together in about 5 minutes. IT IS NOT TESTED ... IT IS ONLY A ROUGH GUESS AT WHAT YOU NEED. As pete said, it is not difficult once you understand the basics.
Code:
Option Explicit
Sub Macro1()
'
'Create an identifier for the Collector Workbook
Dim collector_book As Workbook
'ID for the Workbook Iterator
Dim abook As Workbook
'Create the Collector workbook
Set collector_book = New Workbook
'Iterate through all open workbooks collecting sheets
For Each abook In Workbooks
'Don't regress into the Collector Book!
If abook <> collector_book Then
'Activate each book
abook.Activate
'Copy the sheet
ActiveSheet.Copy After:=collector_book.Sheets(xlLast)
End If
Next
'SaveAs the Collector
collector_book.SaveAs FileName:="C:\Test\JUNK-Collector.xls", FileFormat:= _
xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
, CreateBackup:=False
End Sub
Good Luck and Good Learning!
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|