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

Hello,

I run a macro from currWB which produces the sheet "Overview".

Before I finish my macro, I need to copy this sheet into another workbook
destWB.

I use the following command but gettingthe error "subcript out of range".

Workbooks(currWB).Sheets("Overview").Copy After:=Workbooks(destWB).Sheets.
Count

Any help in this regard please ...???

Sri

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200904/1

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Copy Worksheet

from
Workbooks(currWB).Sheets("Overview").Copy
After:=Workbooks(destWB).Sheets.Count

to

with sheets(destWB)
Workbooks(currWB).Sheets("Overview").Copy _
After:=.Sheets(.sheets.Count)
end with


"Sri via OfficeKB.com" wrote:

Hello,

I run a macro from currWB which produces the sheet "Overview".

Before I finish my macro, I need to copy this sheet into another workbook
destWB.

I use the following command but gettingthe error "subcript out of range".

Workbooks(currWB).Sheets("Overview").Copy After:=Workbooks(destWB).Sheets.
Count

Any help in this regard please ...???

Sri

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200904/1


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Copy Worksheet

Thanks joel for your reply but I still have same problem. See my exact code
as follows.

"Subscript out of range" at "With Sheets(destWB)"

destWB = vPath & "\LCM_Report_" & inpDate & ".xls"
currWB = vPath & "\" & vName

If Dir$(destWB, vbNormal) = "" Then

Workbooks.Add
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=destWB
ActiveWindow.Close SaveChanges:=False
Application.DisplayAlerts = True

With Sheets(destWB)
Workbooks(currWB).Sheets("Overview").Copy _
After:=.Sheets(.Sheets.Count)
End With

End If



joel wrote:
from
Workbooks(currWB).Sheets("Overview").Copy
After:=Workbooks(destWB).Sheets.Count

to

with sheets(destWB)
Workbooks(currWB).Sheets("Overview").Copy _
After:=.Sheets(.sheets.Count)
end with

Hello,

[quoted text clipped - 11 lines]

Sri


--
Message posted via http://www.officekb.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Copy Worksheet

destWBName = vPath & "\LCM_Report_" & inpDate & ".xls"
'currWB = vPath & "\" & vName
Application.DisplayAlerts = False

Set currWb = ActiveWorkbook

If Dir$(destWB, vbNormal) = "" Then

Application.DisplayAlerts = True

'copy without After will create new workbook automatically
currWb.Sheets("Overview").Copy
Set destWB = ActiveWorkbook
currWb.Close savechanges:=False

With destWB
.Sheets("Overview").Copy _
After:=.Sheets(.Sheets.Count)
End With
destWB.SaveAs Filename:=destWBName
End If

"Sri via OfficeKB.com" wrote:

Thanks joel for your reply but I still have same problem. See my exact code
as follows.

"Subscript out of range" at "With Sheets(destWB)"

destWB = vPath & "\LCM_Report_" & inpDate & ".xls"
currWB = vPath & "\" & vName

If Dir$(destWB, vbNormal) = "" Then

Workbooks.Add
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=destWB
ActiveWindow.Close SaveChanges:=False
Application.DisplayAlerts = True

With Sheets(destWB)
Workbooks(currWB).Sheets("Overview").Copy _
After:=.Sheets(.Sheets.Count)
End With

End If



joel wrote:
from
Workbooks(currWB).Sheets("Overview").Copy
After:=Workbooks(destWB).Sheets.Count

to

with sheets(destWB)
Workbooks(currWB).Sheets("Overview").Copy _
After:=.Sheets(.sheets.Count)
end with

Hello,

[quoted text clipped - 11 lines]

Sri


--
Message posted via http://www.officekb.com


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Copy Worksheet

Hello Joel,

Thanks for your reply but unfortunately, your code is not working. Please
find my problem as follows.

Set currWb = ActiveWorkbook -- My present workbook "File A" is assigned to
currWb

currWb.Sheets("Overview").Copy -- A new workbook is created and Overview
sheet is copied into new workbook

Set destWB = ActiveWorkbook -- My present workbook "File A" is assigned to
destWb

currWb.Close savechanges:=False -- My present workbook "File A" is closed
where I have this macro. So, no code after this is executed. At the end, I am
left with a new workbook with name "Book 1" and "Overview" sheet in it,
unsaved.

Any help please... One more this thins that my source workbook contains more
than one sheet out of which I have to copy only selected worksheet.

Thanks
Sri


joel wrote:
destWBName = vPath & "\LCM_Report_" & inpDate & ".xls"
'currWB = vPath & "\" & vName
Application.DisplayAlerts = False

Set currWb = ActiveWorkbook

If Dir$(destWB, vbNormal) = "" Then

Application.DisplayAlerts = True

'copy without After will create new workbook automatically
currWb.Sheets("Overview").Copy
Set destWB = ActiveWorkbook
currWb.Close savechanges:=False

With destWB
.Sheets("Overview").Copy _
After:=.Sheets(.Sheets.Count)
End With
destWB.SaveAs Filename:=destWBName
End If

Thanks joel for your reply but I still have same problem. See my exact code
as follows.

[quoted text clipped - 35 lines]

Sri


--
Message posted via http://www.officekb.com



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Copy Worksheet

You currWB variable is, I assume, a Workbook type variable. Therefore,
you can use it directly instead of Workbooks or you can use its name
with Workbooks. E.g.,

Workbooks(currWB.Name)......

' or

currWB.Sheets.(.....

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Thu, 09 Apr 2009 09:23:18 GMT, "Sri via OfficeKB.com" <u47062@uwe
wrote:

Hello,

I run a macro from currWB which produces the sheet "Overview".

Before I finish my macro, I need to copy this sheet into another workbook
destWB.

I use the following command but gettingthe error "subcript out of range".

Workbooks(currWB).Sheets("Overview").Copy After:=Workbooks(destWB).Sheets.
Count

Any help in this regard please ...???

Sri

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 & paste cells fr open worksheet then close the worksheet Sin Excel Programming 1 October 2nd 06 02:20 PM
Unable to Insert Worksheet/Move and copy worksheet Excel 2003 lukerush Excel Worksheet Functions 2 September 7th 06 05:05 PM
copy range on every worksheet (diff names) to a master worksheet (to be created) Bernie[_2_] Excel Programming 2 September 22nd 04 03:30 PM
copy range on every worksheet (diff names) to a master worksheet (to be created) Bernie[_3_] Excel Programming 0 September 22nd 04 03:26 PM
Code to copy range vs Copy Entire Worksheet - can't figure it out Mike Taylor Excel Programming 1 April 15th 04 08:34 PM


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

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"