Sub choppeImage()
Dim fichier, destination$
destination = Environ("userprofile") & "\DeskTop\"
fichier = Application.GetOpenFilename("Pictures Files (*.jpg;*.png;*.gif), *.jpg;*.png;*.gif", 1, "ouvrir un fichier")
If fichier = False Then Exit Sub
decoupe fichier, destination
End Sub
Sub decoupe(fichierimage, DetinationFolder$)
Dim w As Single, h As Single, shap As Shape, Side&, Nom$, Ext$
Nom = Mid(fichierimage, InStrRev(fichierimage, "\") + 1)
Ext = Right(LCase(fichierimage), 3)
With ActiveSheet
Set shap = .Shapes.AddPicture(fichierimage, False, True, 0, 0, -1, -1)
DoEvents
With shap
w = .Width: h = .Height
For Side = 0 To 1
.PictureFormat.CropLeft = w * IIf(Side = 0, 0.5, 0)
.PictureFormat.CropRight = w * IIf(Side = 0, 0, 0.5)
.CopyPicture
With .Parent.ChartObjects.Add(shap.Left, shap.Top, shap.Width, shap.Height)
.ShapeRange.Line.Visible = msoFalse
Do While .Chart.Pictures.Count = 0: .Chart.Paste: Loop
If Ext = "png" Or Ext = "gif" Then
.Chart.ChartArea.Fill.Visible = msoTrue
.Chart.ChartArea.Fill.Solid
.Chart.ChartArea.Format.Fill.Transparency = 1
End If
.Chart.Export Filename:=DetinationFolder$ & Nom & "_" & IIf(Side = 0, "droite", "gauche") & "." & Ext
.Delete
End With
Next
shap.Delete
End With
End With
End Sub