Excel vba exporting chart blurry on second time -
i using excel vba perform calculation. @ end create chart , put on user form. on first time perform it, works. afterwards, have 'restart' button starts program on again (without terminating it). on second time perform code, picture comes out blurry reason. can see in below code, save picture in documents , saves picture blurry on second time code runs (on first time comes out good). behaviour wierd , can't understand it. here's code saves chart:
private sub showgraphbutton_click() 'creating image chart, saving , displaying in userform dim result chart dim chart_data range dim trend trendline 'setting chart set result = sheet1.shapes.addchart(xlxyscatter).chart set chart_data = sheets("sheet2").range("b2:b10000") 'application.screenupdating = false 'chart settings result 'series settings .seriescollection.newseries .seriescollection(1).name = " " .seriescollection(1).values = chart_data .seriescollection(1).xvalues = sheets("sheet2").range("a2:a10000") .seriescollection(1).markersize = 12 'axes settings .axes(xlcategory, xlprimary).reverseplotorder = false .axes(xlcategory, xlprimary).hastitle = true .axes(xlcategory, xlprimary).axistitle.text = "time (seconds)" .axes(xlcategory, xlprimary).axistitle.font.size = 12 .axes(xlvalue, xlprimary).hastitle = true .axes(xlvalue, xlprimary).axistitle.text = "standarddeviation" .axes(xlvalue, xlprimary).axistitle.font.size = 12 'area settings .chartarea.height = 350 .chartarea.width = 600 .chartarea.format.fill.forecolor.rgb = rgb(183, 207, 255) 'chart title settings .hastitle = true .charttitle.text = "standarddeviation per second" .charttitle.characters.font.bold = true .charttitle.characters.font.color = rgb(0, 0, 0) .charttitle.characters.font.name = "arial" 'legend settings .haslegend = true .legend.position = xllegendpositionleft .legend.includeinlayout = true .legend.height = 20 .legend.width = 100 'trendline settings set trend = .seriescollection(1).trendlines.add trend.displayequation = true trend.displayrsquared = true trend.datalabel.left = 20 end 'creates image dim img_name string img_name = application.defaultfilepath & application.pathseparator & "mychart.jpeg" result.export filename:=img_name, filtername:="jpeg" 'deletes chart sheet1 sheet1.chartobjects(1).delete graphform.picture = loadpicture(img_name) runningmode.hide graphform.show application.screenupdating = true end sub if other information required share accordantly.
firstly, can try saving chart png. results in higher quality image when exporting.
another reason blurriness chart small when exported. try increasing size of chart in following code:
.chartarea.height = 350 .chartarea.width = 600 you'll have increase font sizes, in axis title example, , possibly re-position legend.
another option export chart pdf, vectored file:
private sub btnsavepdf_click() dim filename string, myshell object filename = application.inputbox("enter pdf file name", type:=2) activesheet.chartobjects("refchart").activate activesheet.exportasfixedformat xltypepdf, filename, xlqualitystandard set myshell = createobject("wscript.shell") myshell.run filename end sub source: http://www.vbaexpress.com/forum/archive/index.php/t-33369.html
Comments
Post a Comment