Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Copy & paste cells fr open worksheet then close the worksheet | Excel Programming | |||
Unable to Insert Worksheet/Move and copy worksheet Excel 2003 | Excel Worksheet Functions | |||
copy range on every worksheet (diff names) to a master worksheet (to be created) | Excel Programming | |||
copy range on every worksheet (diff names) to a master worksheet (to be created) | Excel Programming | |||
Code to copy range vs Copy Entire Worksheet - can't figure it out | Excel Programming |