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 to a file in another directory

I want to copy a worksheet in its entirety to a workbook in another
directory. I'm running Excel 2002 & my code (which doesn't work) is
as follows:

Option Explicit

Sub xCopyFGSht()
ActiveSheet.Select
ActiveSheet.Copy after:=Workbooks("022508.xls").Sheets(xlEnd)
ActiveSheet.Move after:=Sheets(Sheets.Count)
End Sub

The active sheet I'm copying is in R:\Batch Sheets, and I want to copy
it to
K:\Cost Accounting\Production\2008\022508.xls.

This is a network, which is why the different drives. Both workbooks
are open.

I get a run-time error '9': "Subscript out of range" error message.

I should state that if I perform this procedure manually the first
time, then try it again using the macro, it works. It's as if it
recognizes the path from one file to the other after I've done it
manually.

Hope I've given all of the facts needed. Any ideas?

Warren
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 897
Default Copy worksheet to a file in another directory

How about

ActiveSheet.Copy After:=Workbooks("K:\Cost
Accounting\Production\2008\022508.xls").Sheets(1)


HTH,
JP


wrote in message
...
I want to copy a worksheet in its entirety to a workbook in another
directory. I'm running Excel 2002 & my code (which doesn't work) is
as follows:

Option Explicit

Sub xCopyFGSht()
ActiveSheet.Select
ActiveSheet.Copy after:=Workbooks("022508.xls").Sheets(xlEnd)
ActiveSheet.Move after:=Sheets(Sheets.Count)
End Sub

The active sheet I'm copying is in R:\Batch Sheets, and I want to copy
it to
K:\Cost Accounting\Production\2008\022508.xls.

This is a network, which is why the different drives. Both workbooks
are open.

I get a run-time error '9': "Subscript out of range" error message.

I should state that if I perform this procedure manually the first
time, then try it again using the macro, it works. It's as if it
recognizes the path from one file to the other after I've done it
manually.

Hope I've given all of the facts needed. Any ideas?

Warren



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 897
Default Copy worksheet to a file in another directory

That should have been

ActiveSheet.Copy After:= _
Workbooks("K:\Cost Accounting\Production
\2008\022508.xls").Sheets(Sheets.Count)


--JP

On Feb 27, 8:25*pm, "JP" wrote:
How about

ActiveSheet.Copy After:=Workbooks("K:\Cost
Accounting\Production\2008\022508.xls").Sheets(1)

HTH,
JP

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Copy worksheet to a file in another directory

or

ActiveSheet.Copy _
After:=Workbooks("022508.xls").Sheets(Workbooks("0 22508.xls").Sheets.Count)

You don't include the drive and path in the workbooks() reference, but you do
want to qualify the Sheets.count.

Or using with/end with:

with workbooks("022508.xls")
ActiveSheet.Copy _
After:=.Sheets(.Sheets.Count)
End with



JP wrote:

That should have been

ActiveSheet.Copy After:= _
Workbooks("K:\Cost Accounting\Production
\2008\022508.xls").Sheets(Sheets.Count)

--JP

On Feb 27, 8:25 pm, "JP" wrote:
How about

ActiveSheet.Copy After:=Workbooks("K:\Cost
Accounting\Production\2008\022508.xls").Sheets(1)

HTH,
JP


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 897
Default Copy worksheet to a file in another directory

Good point, if both workbooks are open then you don't need the path.

Thx,
JP

On Feb 27, 8:57*pm, Dave Peterson wrote:
or

ActiveSheet.Copy _
* After:=Workbooks("022508.xls").Sheets(Workbooks("0 22508.xls").Sheets..Count)

You don't include the drive and path in the workbooks() reference, but you do
want to qualify the Sheets.count.

Or using with/end with:

with workbooks("022508.xls")
* ActiveSheet.Copy _
* * After:=.Sheets(.Sheets.Count)
End with




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Copy worksheet to a file in another directory

If the file is closed, you still don't include the drive/path.

(You'd have to open the file first, though.)

JP wrote:

Good point, if both workbooks are open then you don't need the path.

Thx,
JP

On Feb 27, 8:57 pm, Dave Peterson wrote:
or

ActiveSheet.Copy _
After:=Workbooks("022508.xls").Sheets(Workbooks("0 22508.xls").Sheets.Count)

You don't include the drive and path in the workbooks() reference, but you do
want to qualify the Sheets.count.

Or using with/end with:

with workbooks("022508.xls")
ActiveSheet.Copy _
After:=.Sheets(.Sheets.Count)
End with



--

Dave Peterson
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
Copy worksheet from one file to another pokdbz Excel Discussion (Misc queries) 6 September 28th 07 09:23 PM
Copy worksheet to another file AlanW Excel Programming 3 August 22nd 07 07:30 AM
Can you copy a Excel file to a new directory and rename it? pokdbz Excel Discussion (Misc queries) 1 August 1st 07 08:44 PM
copy part of a worksheet into a worksheet in the same file/keepi. JTB Excel Worksheet Functions 1 September 23rd 06 09:13 AM
copy a worksheet to another xls file Jac[_2_] Excel Programming 2 November 30th 03 05:13 PM


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

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

About Us

"It's about Microsoft Excel"