PC Review


Reply
Thread Tools Rate Thread

Copy every worksheet

 
 
QB
Guest
Posts: n/a
 
      3rd Oct 2009
I need to copy each worksheet from the active workbook into a new workbook.
I've been fighting with the following code and am hoping can point out my
mistake.

Set DataWrkBk = Workbooks(ActiveWorkbook.Name)
Workbooks.Add
Sheets("Sheet1").Select
Set NewWrkBk = ActiveWorkbook
NewWrkBkName = ActiveWorkbook.Name

Windows("Weekly_Stats.xls").Activate
For Each ws In DataWrkBk.Worksheets
wSheet.Copy After:=NewWrkBk.Worksheets(NewWrkBk.Worksheets.Count)
Debug.Print ws.Name
Next ws

It does the first sheet fine and then spits out an error:424 object required
and highlights the wSheet.Copy line? Why would it work once and then stop?

Thank you for the helping hand.

QB
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      3rd Oct 2009
You could try:

datawrkbk.sheets.copy
or
datawkrbk.worksheets.copy

(don't create the "to" workbook first, either. The .copy will do that for you.)

ps.

Set DataWrkBk = Workbooks(ActiveWorkbook.Name)
is the same thing as:
Set DataWrkBk = ActiveWorkbook




QB wrote:
>
> I need to copy each worksheet from the active workbook into a new workbook.
> I've been fighting with the following code and am hoping can point out my
> mistake.
>
> Set DataWrkBk = Workbooks(ActiveWorkbook.Name)
> Workbooks.Add
> Sheets("Sheet1").Select
> Set NewWrkBk = ActiveWorkbook
> NewWrkBkName = ActiveWorkbook.Name
>
> Windows("Weekly_Stats.xls").Activate
> For Each ws In DataWrkBk.Worksheets
> wSheet.Copy After:=NewWrkBk.Worksheets(NewWrkBk.Worksheets.Count)
> Debug.Print ws.Name
> Next ws
>
> It does the first sheet fine and then spits out an error:424 object required
> and highlights the wSheet.Copy line? Why would it work once and then stop?
>
> Thank you for the helping hand.
>
> QB


--

Dave Peterson
 
Reply With Quote
 
john
Guest
Posts: n/a
 
      3rd Oct 2009
If you are attempting to make a copy of the active workbook have you thought
about using SaveCopyAs?

from the help file:

Example
This example saves a copy of the active workbook.

ActiveWorkbook.SaveCopyAs "C:\TEMP\XXXX.XLS"


--
jb


"QB" wrote:

> I need to copy each worksheet from the active workbook into a new workbook.
> I've been fighting with the following code and am hoping can point out my
> mistake.
>
> Set DataWrkBk = Workbooks(ActiveWorkbook.Name)
> Workbooks.Add
> Sheets("Sheet1").Select
> Set NewWrkBk = ActiveWorkbook
> NewWrkBkName = ActiveWorkbook.Name
>
> Windows("Weekly_Stats.xls").Activate
> For Each ws In DataWrkBk.Worksheets
> wSheet.Copy After:=NewWrkBk.Worksheets(NewWrkBk.Worksheets.Count)
> Debug.Print ws.Name
> Next ws
>
> It does the first sheet fine and then spits out an error:424 object required
> and highlights the wSheet.Copy line? Why would it work once and then stop?
>
> Thank you for the helping hand.
>
> QB

 
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
Sending copy worksheet to mailrecipient - mail adress indicated incell in worksheet Snoopy Microsoft Excel Discussion 1 19th Aug 2009 12:51 PM
Unable to Insert Worksheet/Move and copy worksheet Excel 2003 lukerush Microsoft Excel Worksheet Functions 4 7th Sep 2006 05:05 PM
Unable to Insert Worksheet/Move and copy worksheet Excel 2003 lukerush Microsoft Excel Worksheet Functions 0 7th Sep 2006 03:37 PM
copy range on every worksheet (diff names) to a master worksheet (to be created) Bernie Microsoft Excel Programming 2 22nd Sep 2004 03:30 PM
copy range on every worksheet (diff names) to a master worksheet (to be created) Bernie Microsoft Excel Programming 0 22nd Sep 2004 03:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:20 AM.