PC Review


Reply
Thread Tools Rate Thread

Copy Sheets to another workbook

 
 
Robert
Guest
Posts: n/a
 
      18th Dec 2007
Hello,

I am trying to copy over a range of sheets from one workbook to
another but there is an error in my VBA statement.
Could someone tell me what is going wrong?

'Copy Trial Balances worksheet

ChDir "H:\Risk_Management\BarraOne\ConsistancyCheck\Flash Report
Files"
Workbooks.Open Filename:= _
"H:\Risk_Management\BarraOne\ConsistancyCheck\Flash Report
Files\Trials.xls"

For Each sh In ThisWorkbook.Sheets
If sh.Name <> "" Then
sh.Copy
Selection.Copy
After:=Workbooks("ConsistancyTemplate.xls").Sheets("Summary")
Windows("Trials.xls").Activate
ActiveWindow.Close



Many thanks!

Rgds,
Robert
 
Reply With Quote
 
 
 
 
Incidental
Guest
Posts: n/a
 
      18th Dec 2007
Hi Robert

I have changed the code you gave and it seems to work fine (i think!)
it would seem this code is to run from the workbook called
"ConsistancyTemplate.xls" from your code as you only mention two
workbooks and you are opening the other workbook within the code, you
are opening the workbook called "Trails.xls" and you want to copy all
the sheets in this workbook to the original book. In your code you
were copying all the sheets in workbook "ConsistancyTemplate.xls" and
pasting them in this workbook again after the sheet named "Summary" as
this is not the desired effect i have changed this.

You use ChDir in your code to change the directory which i took out as
you don't need to change the directory if you are going to give the
full path in the workbook open event.

I also change the ThisWorkbook to ActiveWorkbook as ThisWorkbook is
referring to the workbook that is running the code which results in
you copying the sheets to the end of the same workbook.

Workbooks.Open Filename:= _
"C:\Risk_Management\BarraOne\" _
& "ConsistancyCheck\Flash Report Files\Trials.xls"

For Each sh In ActiveWorkbook.Sheets

If sh.Name <> "" Then

sh.Copy
After:=Workbooks("ConsistancyTemplate.xls").Sheets("Summary")

End If

Next sh

Windows("Trials.xls").Activate

ActiveWindow.Close

I hope this helps you out

Steve
 
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
Copy two sheets from workbook & create new workbook Mike R. Microsoft Excel Programming 8 7th Aug 2009 07:09 PM
Re: Copy all worksheets to another workbook, excl. duplicate sheets already in other workbook Chip Pearson Microsoft Excel Programming 0 26th May 2009 04:27 PM
Copy Two Visible Ranges (From Two Sheets) To A New Workbook (AlsoWith Two Sheets) septhemis@gmail.com Microsoft Excel Programming 3 30th Jan 2009 04:20 PM
Re: Copy Two Visible Ranges (From Two Sheets) To A New Workbook (AlsoWith Two Sheets) septhemis@gmail.com Microsoft Excel Programming 0 29th Jan 2009 01:35 PM
copy sheets in workbook to new workbook Ctech Microsoft Excel Programming 1 23rd Nov 2005 08:09 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:53 PM.