vba - Trouble referencing temporary, unsaved workbook when copying worksheets -
vba - Trouble referencing temporary, unsaved workbook when copying worksheets -
i have bunch of worksheets want re-create new, temporary workbook -- without saving it.
worksheet.copy copies worksheet new, unnamed'ish (book1, book2, book3, etc) workbook. want sheets copied same workbook. worksheets after first, have tried using worksheet.copy after:=xlwb.sheets(1)
, not know how reference newly created workbook when setting xlwb workbook-object. maintain receiving run-time error 9, 'subscript out of range'.
i appreciate help can give.
edit: next relevant dims:
dim xlapp excel.application dim xlwb excel.workbook dim xlwbold string dim xlws excel.worksheet dim xlwbnew excel.workbook dim xlwsold excel.worksheet dim xlrng excel.range dim xlrngold excel.range xlwbold = activeworkbook.name set xlapp = new excel.application xlapp.visible = true '*** quite of import set excel.visible,_ 'otherwise user wouldn't see application's running _ 'even though run background xlapp.application.screenupdating = false set xlwb = xlapp.workbooks.add 'create new workbook set xlws = xlwb.worksheets.add
and worksheets should copied:
select case strrpttype case "daily" xlws.name = "1-daily price" 'check lastly column , lastly row llastrow = obasic.getlast(, "dailyrpt", false, "a") ilastcol = obasic.getlast(, "dailyrpt", true, 4) set xlrngold = wksdailyrpt.range(wksdailyrpt.cells(4, 1), wksdailyrpt.cells(llastrow, ilastcol)) application.screenupdating = true xlrngold.copy set xlrng = xlws.cells(1, 1) xlrng.pastespecial paste:=xlpastevalues xlws.columns.autofit each xlwsold in activeworkbook.worksheets if xlwsold.name = "forwardprices" or xlwsold.name = "forwardvolatilities" _ or xlwsold.name = "forwardreturns" or xlwsold.name = "forwardcorrelations" sheets(xlwsold.name).copy after:=workbooks(xlwb).sheets(1) end if next xlwsold end select
this little macro goes through sheets of open workbooks, , copies them after current sheet.
sub gatherallsheets() dim wb workbook, sh worksheet each wb in workbooks if not wb thisworkbook each sh in wb.worksheets sh.copy after:=activesheet next sh end if next wb end sub
is need? or need re-create content of sheets on same sheet?
vba object excel-vba copy worksheet-function
Comments
Post a Comment