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.
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