VBA Code to set chart area as per the image

aayaanmayank

Board Regular
Joined
Jul 20, 2018
Messages
156
Hi I have a vba code which export image from excel to desktop. i am using chart object to save on desktop. however when it saves then image height and width set as per chart area.
is there any way to increase the Chartplot area.

below is the code which i am using.
VBA Code:
Sub Export()
     Dim MyChart As String, MyPicture As String
     Dim PicWidth As Long, PicHeight As Long
     Dim shp As Shape
     Dim ws As Worksheet
Set ws = ActiveSheet
For Each shp In ws.Shapes
    If shp.Type = msoPicture Then
        '        MsgBox shp.Name & " is a picture"
    shp.Select
    End If
Next shp
  '   On Error GoTo Finish
     MyPicture = Selection.Name
     With Selection
           PicHeight = .ShapeRange.Height
           PicWidth = .ShapeRange.Width
     End With
     Charts.Add
'ActiveChart.HeightPercent = 100
'Legend.includeLayout = True
 ActiveChart.Legend.IncludeInLayout = True
 ActiveChart.Legend.Position = xlLegendPositionRight
     ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
     Selection.Border.LineStyle = xlContinuous
     MyChart = Selection.Name & " " & Split(ActiveChart.Name, " ")(2)
    strpath = Environ("USERPROFILE") & "\Desktop\"
     With ActiveSheet
           With .Shapes(MyChart)
                 .Width = PicWidth
                 .Height = PicHeight
           End With
           .Shapes(MyPicture).Copy
           With ActiveChart
                 .ChartArea.Select
                 .Paste
                 .Shapes(1).PictureFormat.CropLeft = 1
                 .Shapes(1).PictureFormat.CropTop = 1
           End With
             .ChartObjects(1).Chart.Export FileName:=strpath & "MyPic.bmp", Filtername:="bmp"
            .Shapes(MyChart).Cut
     End With
     Application.ScreenUpdating = True
     send1
     Exit Sub
End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,231
Messages
5,768,938
Members
425,506
Latest member
AndreaWorkPlace

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
Top