PC Review


Reply
Thread Tools Rate Thread

Copying Worksheets in Different Books to One Workbook

 
 
ajd
Guest
Posts: n/a
 
      29th Jul 2009
I have a list of Workbook paths and adjacent to it a list of Worksheets. I
want to copy the listed worksheets which are all in different workbooks into
a single, new workbook. This is the code I have so far:

Sub MasterBook()

ActiveWorkbook.Sheets("Master").Select
Cells.Select
Selection.Copy
Set wso = Application.Workbooks.Add
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks:=Fasle, Transpose:=False
RowCount = 11
Do While Range("A" & RowCount) <> ""
If Range("D" & RowCount) = "yes" Then
Set BookName = Range("L" & RowCount)
Set SheetName = Range("M" & RowCount)
Workbooks(BookName).Sheets(SheetName).Copy Before:=wso.Sheets(1)
End If

RowCount = RowCount + 1
Loop

End Sub

Range L has the workbook name in the form of a full file path. The file
path has worked for another macro which I used to create that file. Range M
has the worksheet name. In column D is where I identify whether I want to
bring in that specific sheet or not. It's getting hung up in the
Workbooks(BookName)... line with a type mismatch.

Please help with this code or suggest an alternative way of doing this.
Thank you very much for your help!
 
Reply With Quote
 
 
 
 
ryguy7272
Guest
Posts: n/a
 
      29th Jul 2009
You can certainly do this, but you'll have to put in a little time to get it
right. Look at these resources:
http://www.rondebruin.nl/copy2.htm
http://www.rondebruin.nl/copy3.htm
http://www.rondebruin.nl/fso.htm

HTH,
Ryan---


--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"ajd" wrote:

> I have a list of Workbook paths and adjacent to it a list of Worksheets. I
> want to copy the listed worksheets which are all in different workbooks into
> a single, new workbook. This is the code I have so far:
>
> Sub MasterBook()
>
> ActiveWorkbook.Sheets("Master").Select
> Cells.Select
> Selection.Copy
> Set wso = Application.Workbooks.Add
> Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
> SkipBlanks:=Fasle, Transpose:=False
> RowCount = 11
> Do While Range("A" & RowCount) <> ""
> If Range("D" & RowCount) = "yes" Then
> Set BookName = Range("L" & RowCount)
> Set SheetName = Range("M" & RowCount)
> Workbooks(BookName).Sheets(SheetName).Copy Before:=wso.Sheets(1)
> End If
>
> RowCount = RowCount + 1
> Loop
>
> End Sub
>
> Range L has the workbook name in the form of a full file path. The file
> path has worked for another macro which I used to create that file. Range M
> has the worksheet name. In column D is where I identify whether I want to
> bring in that specific sheet or not. It's getting hung up in the
> Workbooks(BookName)... line with a type mismatch.
>
> Please help with this code or suggest an alternative way of doing this.
> Thank you very much for your help!

 
Reply With Quote
 
ajd
Guest
Posts: n/a
 
      29th Jul 2009
I was able to adapt that to generally achieve what I was looking for. Thanks.

"ryguy7272" wrote:

> You can certainly do this, but you'll have to put in a little time to get it
> right. Look at these resources:
> http://www.rondebruin.nl/copy2.htm
> http://www.rondebruin.nl/copy3.htm
> http://www.rondebruin.nl/fso.htm
>
> HTH,
> Ryan---
>
>
> --
> Ryan---
> If this information was helpful, please indicate this by clicking ''Yes''.
>
>
> "ajd" wrote:
>
> > I have a list of Workbook paths and adjacent to it a list of Worksheets. I
> > want to copy the listed worksheets which are all in different workbooks into
> > a single, new workbook. This is the code I have so far:
> >
> > Sub MasterBook()
> >
> > ActiveWorkbook.Sheets("Master").Select
> > Cells.Select
> > Selection.Copy
> > Set wso = Application.Workbooks.Add
> > Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
> > SkipBlanks:=Fasle, Transpose:=False
> > RowCount = 11
> > Do While Range("A" & RowCount) <> ""
> > If Range("D" & RowCount) = "yes" Then
> > Set BookName = Range("L" & RowCount)
> > Set SheetName = Range("M" & RowCount)
> > Workbooks(BookName).Sheets(SheetName).Copy Before:=wso.Sheets(1)
> > End If
> >
> > RowCount = RowCount + 1
> > Loop
> >
> > End Sub
> >
> > Range L has the workbook name in the form of a full file path. The file
> > path has worked for another macro which I used to create that file. Range M
> > has the worksheet name. In column D is where I identify whether I want to
> > bring in that specific sheet or not. It's getting hung up in the
> > Workbooks(BookName)... line with a type mismatch.
> >
> > Please help with this code or suggest an alternative way of doing this.
> > Thank you very much for your help!

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: copying all worksheets into one workbook =?Utf-8?B?SkxHV2hpeg==?= Microsoft Excel Programming 1 28th Mar 2007 01:18 AM
copying worksheets to a new workbook without formulae referencing original workbook pjdeeb@gmail.com Microsoft Excel Programming 2 16th Oct 2006 07:31 PM
Copying worksheets to a new workbook =?Utf-8?B?Y3NpbW9udA==?= Microsoft Excel Misc 4 8th Feb 2006 08:44 PM
Trouble copying worksheets between books - is there size limit? =?Utf-8?B?a3JpczJ1?= Microsoft Excel Worksheet Functions 2 13th Oct 2005 08:44 PM
Copying Worksheets from 1 Workbook to another cwieman Microsoft Excel Programming 4 20th Nov 2003 01:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:33 AM.