Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copy Worksheet Function

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Copy Worksheet Function

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


" 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
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
I want to copy the same image into worksheet with a function Garry Excel Worksheet Functions 1 January 7th 10 11:28 PM
My copy worksheet function doesn't work Sasssygirrll Excel Discussion (Misc queries) 0 January 9th 07 06:12 PM
Is there a function to copy an entire worksheet? nickclingan Excel Worksheet Functions 3 December 23rd 05 03:23 PM
copy worksheet with formulas and vba function Gixxer_J_97[_2_] Excel Programming 3 March 10th 05 08:32 PM
formula/function to copy from worksheet to worksheet Jen Excel Programming 5 January 11th 05 08:22 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"