Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Combining workbooks into one?????

Hi,

I often receive data in several workbooks that i have to open and cop
to a new workbook so as to be able to evaluate the data in compariso
with each other.

Is it possible to use programming (or any other way) to simplify th
process so that on clicking a button or running a macro will collec
each of the sheets from the desired workbooks and copy them to a ne
workbook?

Any help would be much appreciate

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Combining workbooks into one?????

Sub GetSheets()
Dim sPath as Path, i as long
Dim varr as Variant
Dim wkbk as Workbook
sPath = "C:\MyData\"
varr = ("Data1.xls", "Data2.xls", "Data3.xls")
for i = lbound(varr) to ubound(varr)
set wkbk = workbooks.open(sPath & varr(i))
wkbk.worksheets(1).Copy After:=Thisworkbook. _
Worksheets(thisworkbook.Worksheets.count)
wkbk.close SaveChanges:=False
Next
End sub

would be a simple example.

--
Regards,
Tom Ogilvy


ian123 wrote in message
...
Hi,

I often receive data in several workbooks that i have to open and copy
to a new workbook so as to be able to evaluate the data in comparison
with each other.

Is it possible to use programming (or any other way) to simplify the
process so that on clicking a button or running a macro will collect
each of the sheets from the desired workbooks and copy them to a new
workbook?

Any help would be much appreciated


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Combining workbooks into one?????

Thanks for the help. Unfortunately when running the macro the first
line is being rejected as "Compile Error- User Defined Type Not
Defined"

Any ideas as to where i'm going wrong?

Also the line "varr = (Data1.xls, Data2.xls") is highlighted in red and
i am informed that "Compile Error - Expected )" with the first ','
highlighted?


---
Message posted from http://www.ExcelForum.com/

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Combining workbooks into one?????

varr = ("Data1.xls", "Data2.xls", "Data3.xls")
should be
varr = Array("Data1.xls", "Data2.xls", "Data3.xls")

--
Regards,
Tom Ogilvy

ian123 wrote in message
...
Thanks for the help. Unfortunately when running the macro the first
line is being rejected as "Compile Error- User Defined Type Not
Defined"

Any ideas as to where i'm going wrong?

Also the line "varr = (Data1.xls, Data2.xls") is highlighted in red and
i am informed that "Compile Error - Expected )" with the first ','
highlighted?


---
Message posted from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Combining workbooks into one?????

Thanks very much, that solves the 2nd of the 2 problems but
unfortunately i am still being told that the first line of code "Dim
sPath As Path, i As Long" is a compile error, user defined type is not
defined. The words "sPath As Path" are highlighted in blue.

Any advice?


---
Message posted from http://www.ExcelForum.com/



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Combining workbooks into one?????

sPath as String

--
Regards,
Tom Ogilvy

ian123 wrote in message
...
Thanks very much, that solves the 2nd of the 2 problems but
unfortunately i am still being told that the first line of code "Dim
sPath As Path, i As Long" is a compile error, user defined type is not
defined. The words "sPath As Path" are highlighted in blue.

Any advice?


---
Message posted from http://www.ExcelForum.com/



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Combining workbooks into one?????

Thanks very much, i can now get it to bring the first sheet of each book
in the range selected. Is it possible to bring all the sheets from
each of the books selected into the new book?

Once again thanks very much for your help on this - it is very much
appreciated


---
Message posted from http://www.ExcelForum.com/

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Combining workbooks into one?????

Sub GetSheets()
Dim sPath As String, i As Long
Dim varr As Variant
Dim wkbk As Workbook
sPath = "C:\MyData\"
varr = Array("Data1.xls", "Data2.xls", "Data3.xls")
For i = LBound(varr) To UBound(varr)
Set wkbk = Workbooks.Open(sPath & varr(i))
wkbk.Worksheets.Copy After:=ThisWorkbook. _
Worksheets(ThisWorkbook.Worksheets.Count)
wkbk.Close SaveChanges:=False
Next
End Sub

--
Regards,
Tom Ogilvy


ian123 wrote in message
...
Thanks very much, i can now get it to bring the first sheet of each book
in the range selected. Is it possible to bring all the sheets from
each of the books selected into the new book?

Once again thanks very much for your help on this - it is very much
appreciated


---
Message posted from http://www.ExcelForum.com/



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Combining workbooks into one?????

Thanks - that's fantastic. Your help is very much appreciate

--
Message posted from http://www.ExcelForum.com

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Combining workbooks into one?????

Thats a great macro... Is there a way to tweak it so that it will
combine approx 300 xl files with different names (of a sequence) into 1
file?

Could it also be modified to put the data in the next available column
of the same sheet?


Thanks!


---
Message posted from http://www.ExcelForum.com/



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Combining workbooks into one?????

Change this line:

wkbk.Worksheets(1).Copy After:=ThisWorkbook. _
Worksheets(ThisWorkbook.Worksheets.Count)

to

wkbk.Worksheets.Copy After:=ThisWorkbook. _
Worksheets(ThisWorkbook.Worksheets.Count)



ian123 wrote:

Thanks very much, i can now get it to bring the first sheet of each book
in the range selected. Is it possible to bring all the sheets from
each of the books selected into the new book?

Once again thanks very much for your help on this - it is very much
appreciated

---
Message posted from http://www.ExcelForum.com/


--

Dave Peterson

  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Combining workbooks into one?????

I have been monitoring this thread with considerable interest. I've
been trying to figure out what code needed after they are copied to
rename each worksheet using a numeric value that appears in cell C2 of
each sheet as the name. The value in cell C2 is unique for each
worksheet. Any help is appreciated.

The code I am using is as follows:

Sub GetSheets()
Dim sPath As String, i As Long
Dim varr As Variant
Dim wkbk As Workbook
sPath = "C:\Data\DataFiles\test\"
varr = Array("Data1.xls", "Data2.xls", "Data3.xls")
For i = LBound(varr) To UBound(varr)
Set wkbk = Workbooks.Open(sPath & varr(i))
wkbk.Worksheets(6).Copy After:=ThisWorkbook. _
Worksheets(ThisWorkbook.Worksheets.Count)
wkbk.Close SaveChanges:=False
Next
End Sub
Dave Peterson wrote in message ...
Change this line:

wkbk.Worksheets(1).Copy After:=ThisWorkbook. _
Worksheets(ThisWorkbook.Worksheets.Count)

to

wkbk.Worksheets.Copy After:=ThisWorkbook. _
Worksheets(ThisWorkbook.Worksheets.Count)



ian123 wrote:

Thanks very much, i can now get it to bring the first sheet of each book
in the range selected. Is it possible to bring all the sheets from
each of the books selected into the new book?

Once again thanks very much for your help on this - it is very much
appreciated

---
Message posted from http://www.ExcelForum.com/

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
Combining several workbooks rwaldsmith Excel Discussion (Misc queries) 1 June 13th 08 12:17 AM
Combining Workbooks banjoread Excel Discussion (Misc queries) 4 November 14th 06 03:56 PM
combining 2 workbooks Dana Excel Discussion (Misc queries) 0 March 22nd 06 09:44 PM
combining workbooks Fawn Excel Worksheet Functions 0 April 13th 05 03:24 AM
Combining workbooks RC Excel Discussion (Misc queries) 2 December 21st 04 10:15 AM


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