Increase resolution of Exporting a Chart as a Picture using VBA

bofonomo

Board Regular
Joined
Feb 4, 2010
Messages
114
Hi All,

I have used this VBA to export charts from my work sheet. I will expland on this to export all charts, however when the charts are exported it exports a picture of the same size as the chart. Which means when using it in a document the quality is not very good.

I have tried to get round this by increasing the size of the graph manually, but all the points stay the same size, and the font, so it'll mean I have to alter everything.

Is there any way of just increasing the export size/resolution?


Dim oCht As Chart
ActiveSheet.ChartObjects("Chart 3").Select
Set oCht = ActiveChart
On Error GoTo Err_Chart
oCht.Export Filename:="C:\Documents and Settings\All Users\Desktop\Chart1.png", Filtername:="png"

Err_Chart:
If Err <> 0 Then
Debug.Print Err.Description
Err.Clear
End If

Chears
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
You have to copy your chart as a picture (use oChart.Chart.CopyPicture xlScreen, xlPicture) and then pasting it into another blank chart. Then when you scale this new chart all the elements in the picture would also be scaled up.

Something like this:
VBA Code:
                    oChart.Chart.CopyPicture xlScreen, xlPicture
                    DoEvents
                    lWidth = oChart.Width
                    lHeight = oChart.Height
                    Set chrt = ActiveSheet.ChartObjects.Add(Left:=0, Top:=0, Width:=lWidth, Height:=lHeight)
                    chrt.Activate
                    ActiveSheet.Shapes(chrt.Name).Line.Visible = msoFalse
                    ActiveSheet.Shapes(chrt.Name).Fill.Visible = msoFalse
                    DoEvents
                    
                    With chrt.Chart
                      .Paste
                      ActiveSheet.Shapes(chrt.Name).ScaleWidth 4, msoFalse, msoScaleFromTopLeft
                      ActiveSheet.Shapes(chrt.Name).ScaleHeight 4, msoFalse, msoScaleFromTopLeft
                      .Export strFname
                    End With
                    chrt.Delete
 
Upvote 0

Forum statistics

Threads
1,224,612
Messages
6,179,890
Members
452,948
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top