EXCEL 2010 VBA copying graphs -
so confused on how excel copy/ paste works. have code copies 1 graph picture , paste's in new sheet.
worksheets(redemp).chartobjects("chart 6").copypicture pasterow = pasterow + 24 worksheets("print").cells(pasterow, 2).select worksheets("print").paste
if run macro manually works of time (with multiple excel files opened) if run macro via vb script , no other excel file open works of time. if run macro via vb script , excel file open code works 20% of time , 80% of time 'run time error 1004: paste paste method of worksheet class failed
i did quite bit of research have not found solution yet. appreciated.
code
private sub changeandcopy() 'changes company in "debt redemption sheet" , copy/paste's (info , redemption tables , chart) new sheet 'create variables sheet names dim redemp, auxil, pdf string redemp = "debt redemptions profile" auxil = "auxiliary" pdf = "print" 'call sub takes sheet name input , sets row height, font height , printing margins call pagesetup(pdf, 10, 6) 'set variables pasting in printing sheet (pastecol/row) dim issuer_row1, issuer_rowl, i, pasterow integer pastecol = 1 pasterow = 1 'find rows of variables in auxiliarry sheet company names used in loop issuer_row1 = 3 issuer_rowl = worksheets(auxil).cells(3, 2).end(xldown).row worksheets(redemp).cells(8, 4).value = year(date) worksheets(redemp).cells(10, 4).value = "both" = issuer_row1 issuer_rowl 'changes copany in the sheet "debt redemptions profile" worksheets(redemp).cells(6, 4).value = worksheets(auxil).cells(i, 2).value 'finds issuer code in auxiliarry sheet issuercode = worksheets(auxil).cells(i, 3).value 'copies range info data (company name, year, etc.) worksheets(redemp).range("b3:d11").copy worksheets("print").cells(pasterow, pastecol).pastespecial xlpastevalues 'andnumberformats worksheets("print").cells(pasterow, pastecol).pastespecial xlpasteformats 'copies maturity profile worksheets(redemp).range("f3:n25").copy pasterow = pasterow + 10 worksheets(pdf).cells(pasterow, pastecol).pastespecial xlpastevalues 'andnumberformats worksheets(pdf).cells(pasterow, pastecol).pastespecial xlpasteformats **'copies chart worksheets(redemp).chartobjects("chart 6").copypicture pasterow = pasterow + 24 worksheets(pdf).cells(pasterow, pastecol + 1).activate worksheets(pdf).paste** 'call sub filters maturing debts according issuer code , copies , paste's result in print sheet pasterow = pasterow + 22 call filtersheet(issuercode, pasterow, 2) worksheets(pdf).cells(pasterow - 1, 1).value = "redemptions schedule 6 months ahead" worksheets(pdf).cells(pasterow - 1, 1).font.bold = true pasterow = pasterow + 21 next end sub
try this:
activeworkbook.worksheets(redemp).chartobjects("chart 6").copypicture pasterow = pasterow + 24 activeworkbook.worksheets("print").cells(pasterow, 2).pastespecial
Comments
Post a Comment