Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Copying Worksheet to Another Open Workbook

I have a worksheet named "Temp" that resides in a Workbook called
"BaseFile.xls". I'm trying to copy it to another workbook whose name I
have stored in a string fStr.

Here's what I have:

Windows("BaseFile.xls").Activate
Sheets("Temp").Copy After:=Workbooks(fStr).Sheets(1)

But I'm getting a subscript out of range problem with fStr in
Workbooks....

Could someone tell me what the correct code should be.
Most appreciated.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Copying Worksheet to Another Open Workbook

I'd use the workbooks collection (instead of windows):

Workbooks("BaseFile.xls").workSheets("Temp").Copy _
After:=Workbooks(fStr).Sheets(1)

But what's in fStr?

If you don't include the .xls, start including it.
If you include the path, don't.

And is the workbook named fStr open?


" wrote:

I have a worksheet named "Temp" that resides in a Workbook called
"BaseFile.xls". I'm trying to copy it to another workbook whose name I
have stored in a string fStr.

Here's what I have:

Windows("BaseFile.xls").Activate
Sheets("Temp").Copy After:=Workbooks(fStr).Sheets(1)

But I'm getting a subscript out of range problem with fStr in
Workbooks....

Could someone tell me what the correct code should be.
Most appreciated.


--

Dave Peterson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Copying Worksheet to Another Open Workbook

Hi Marston,

Your code should work.

If the two workbooks are open and the Temp sheet exists, you should look at
the possibility that the name of one or other of these may be mis-spelled in
your code - a subtle error such as a missing or added space perhaps?

Once you have resolved this, you could drop the activation, fully qualify
the worksheet name and, as Dave suggested, use the Workbooks collection:


Sub Tester03()
Dim fStr As String
fStr = "MyOtherWorkbook.xls"

Workbooks("BaseFile.xls").Sheets("Temp").Copy _
After:=Workbooks(fStr).Sheets(1)
End Sub


---
Regards,
Norman



" wrote in message
...
I have a worksheet named "Temp" that resides in a Workbook called
"BaseFile.xls". I'm trying to copy it to another workbook whose name I
have stored in a string fStr.

Here's what I have:

Windows("BaseFile.xls").Activate
Sheets("Temp").Copy After:=Workbooks(fStr).Sheets(1)

But I'm getting a subscript out of range problem with fStr in
Workbooks....

Could someone tell me what the correct code should be.
Most appreciated.



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
Copying worksheet to another workbook Dig Excel Worksheet Functions 3 October 30th 08 09:01 PM
Copying a worksheet into the same workbook Michael New Users to Excel 9 February 6th 06 08:35 PM
Copying A Worksheet From Each Open Workbook to an new Workbook carl Excel Worksheet Functions 1 January 3rd 06 05:37 PM
Copying worksheet from workbook to another Mark Jackson Excel Worksheet Functions 0 January 14th 05 09:05 PM
Copying worksheet to another workbook Haider Quazilbash Excel Programming 2 September 22nd 03 06:23 PM


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

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"