vba - Copy charts to userform multipage pages in runtime -
i have data in worksheet need create charts. these charts going populate different pages of multipage in userform. these pages need populated in sequence charts created.
i have no difficulty charts , creating image them. can copy image first page (it has image object). in order create new page, i'm using following code:
multipage1.pages.add multipage1.pages(0).controls.copy multipage1.pages(k).paste
when copy controls, copies previous image. shouldn't problem long new image gets replaced newly created chart image. problem is, new chart being copied first page, not last 1 created (but not case... don't understand). tried force selection of new page using userform2.multipage1.value = k
it's still not working.
here code wrote:
dim mychart chart dim chartdata range dim chartname string dim thiswb workbook dim imagename string dim ncolunas long dim i, j, k integer set thiswb = thisworkbook k = 0 thiswb.sheets(3) ncolunas = .cells(2, .columns.count).end(xltoleft).column = 1 ncolunas - 1 step 3 if > 1 multipage1.pages.add multipage1.pages(0).controls.copy multipage1.pages(k).paste end if set chartdata = .range(.cells(2, i), .cells(95, i)) set mychart = .shapes.addchart(xlxyscatterlines).chart mychart.seriescollection(1).values = chartdata mychart.seriescollection(1).xvalues = .range(.cells(2, + 1), .cells(95, + 1)) imagename = application.defaultfilepath & application.pathseparator & "tempchart.gif" mychart.export filename:=imagename, filtername:="gif" .chartobjects(1).delete userform2.multipage1.value = k userform2.image1.picture = loadpicture(imagename) kill imagename k = k + 1 next end
if have 4 charts display, final result be: chart4/chart1/chart2/chart3 instead of chart1/chart2/chart3/chart4
nevermind, solved it! instead of using image object inside each page of multipage1, removed them , replaced
userform2.image1.picture = loadpicture(imagename)
with
userform2.multipage1.pages(k).picture = loadpicture(imagename)
Comments
Post a Comment