Report

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

Ask a question juancarlosmm 2Posts Tuesday October 25, 2016Registration date October 25, 2016 Last seen - Last answered on Oct 25, 2016 05:04PM
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
See more 
Helpful
+0
moins plus
Thank you all,
I found the solution here
http://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
Add comment

Member requests are more likely to be responded to.

Members can monitor the statuses of their requests from their account pages.

A CCM membership gives you access to additional options.

Not a member yet?

Sign up now. It takes less than a minute and is completely free!