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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,223,270
Messages
6,171,102
Members
452,379
Latest member
IainTru

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