PC Review


Reply
Thread Tools Rate Thread

Copy Worksheet Function

 
 
Adam.Sheehy@gmail.com
Guest
Posts: n/a
 
      19th Nov 2007
Hi guys!
I have some code to copy a certain worksheet within a workbook to
another workbook:
....
MYSHEET.Copy
ActiveWorkbook.SaveAs strSaveName
ActiveWorkbook.Close
....

According to the help docs using copy with no "before" or "after" will
copy the worksheet to a new workbook (which is what I want it to do).
The problem is that if I don't protect the structure of the original
workbook - let's call it "WorkBook A" - then "WorkBook A" remains
active and saves itself as a new name (strSaveName). I stepped through
the code slowly and noticed that WorkBook A just minimizes in Excel
but still remains in the foreground and the new copy pops up but
remains in the background... Is there a way around this so I don't
have to protect the workbook... or some other code to do what I want?

Hope this makes sense.
Thanks for viewing.

-Adam.
 
Reply With Quote
 
 
 
 
=?Utf-8?B?T3NzaWVNYWM=?=
Guest
Posts: n/a
 
      19th Nov 2007
When you copy a worksheet to another workbook, the workbook to which it is
copied becomes the active workbook. there is a good reason for this because
you need to be able to identify it and you can do this wirh activeworkbook
and assign it to a variable. The following code (untested) should help:-

Dim MYSHEET As Worksheet
Dim wbAct As Workbook
Dim wbNew As Workbook

Set wbAct = ActiveWorkbook

Set MYSHEET = ActiveSheet

MYSHEET.Copy
Set wbNew = ActiveWorkbook
wbAct.SaveAs strSaveName
wbAct.Close
--
Regards,

OssieMac


"(E-Mail Removed)" wrote:

> Hi guys!
> I have some code to copy a certain worksheet within a workbook to
> another workbook:
> ....
> MYSHEET.Copy
> ActiveWorkbook.SaveAs strSaveName
> ActiveWorkbook.Close
> ....
>
> According to the help docs using copy with no "before" or "after" will
> copy the worksheet to a new workbook (which is what I want it to do).
> The problem is that if I don't protect the structure of the original
> workbook - let's call it "WorkBook A" - then "WorkBook A" remains
> active and saves itself as a new name (strSaveName). I stepped through
> the code slowly and noticed that WorkBook A just minimizes in Excel
> but still remains in the foreground and the new copy pops up but
> remains in the background... Is there a way around this so I don't
> have to protect the workbook... or some other code to do what I want?
>
> Hope this makes sense.
> Thanks for viewing.
>
> -Adam.
>

 
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
I want to copy the same image into worksheet with a function Garry Microsoft Excel Worksheet Functions 1 7th Jan 2010 11:28 PM
(VBA Function ?) Lookup value and copy it into antoher worksheet beety007@gmail.com Microsoft Excel Programming 1 25th Dec 2006 10:20 PM
Is there a function to copy an entire worksheet? nickclingan Microsoft Excel Worksheet Functions 3 23rd Dec 2005 03:23 PM
copy worksheet with formulas and vba function =?Utf-8?B?R2l4eGVyX0pfOTc=?= Microsoft Excel Programming 3 10th Mar 2005 08:32 PM
formula/function to copy from worksheet to worksheet =?Utf-8?B?SmVu?= Microsoft Excel Programming 5 11th Jan 2005 08:22 PM


Features
 

Advertising
 

Newsgroups
 


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