Insert Picture in Excel macro, after crop it, save it to a file

Solved/Closed
juancarlosmm Posts 2 Registration date Tuesday October 25, 2016 Status Member Last seen October 25, 2016 - Oct 25, 2016 at 02:06 PM
juancarlosmm Posts 2 Registration date Tuesday October 25, 2016 Status Member Last seen October 25, 2016 - Oct 25, 2016 at 05:04 PM
Hello friends, I need to open a macro, after place the name in A1 cell, push a button to insert a picture, base on A1 name, then, after crop it and resize it, save just the cropped picture to a new file named A1 & "b".jpg
Related:

1 response

juancarlosmm Posts 2 Registration date Tuesday October 25, 2016 Status Member Last seen October 25, 2016
Oct 25, 2016 at 05:04 PM
Thank you all,
I found the solution here
https://stackoverflow.com/questions/18232987/export-pictures-from-excel-file-into-jpg-using-vba

Here is the code, regards

Option Explicit

Sub ExportMyPicture()

Dim MyChart As String, MyPicture As String
Dim PicWidth As Long, PicHeight As Long

Application.ScreenUpdating = False
On Error GoTo Finish

MyPicture = Selection.Name
With Selection
PicHeight = .ShapeRange.Height
PicWidth = .ShapeRange.Width
End With

Charts.Add
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
Selection.Border.LineStyle = 0
MyChart = Selection.Name & " " & Split(ActiveChart.Name, " ")(2)

With ActiveSheet
With .Shapes(MyChart)
.Width = PicWidth
.Height = PicHeight
End With

.Shapes(MyPicture).Copy

With ActiveChart
.ChartArea.Select
.Paste
End With

.ChartObjects(1).Chart.Export Filename:="MyPic.jpg", FilterName:="jpg"
.Shapes(MyChart).Cut
End With

Application.ScreenUpdating = True
Exit Sub

Finish:
MsgBox "You must select a picture"
End Sub
0