VBA Code to set chart area as per the image

aayaanmayank

Board Regular
Joined
Jul 20, 2018
Messages
157
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

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Forum statistics

Threads
1,215,025
Messages
6,122,734
Members
449,094
Latest member
dsharae57

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