Private Sub Worksheet_Change(ByVal Target As Range)
Set images = Sheets("logos")
If Target.Column = colonne And Target.Count = 1 Then
'-- suppression
For Each s In ActiveSheet.Shapes
If s.Type = 13 Then
If s.TopLeftCell.Address = Target.Address Then s.Delete
End If
Next s
If Target <> "" Then
On Error Resume Next
images.Shapes(Target).Copy
If Err = 0 Then
ActiveSheet.Paste
Selection.OnAction = "ClicImage"
Selection.Name = "Image" & ActiveCell.Row
PlaceTheShapeInCenterRange Target, ActiveSheet.Shapes("Image" & ActiveCell.Row), 10'10% de réduction
Target.Select
End If
End If
End If
End Sub
Sub PlaceTheShapeInCenterRange(rng As Range, shap, Optional marge As Long = 0) 'la marge exprime un pourcentage de 1 à x%
Dim Ratio#
Ratio = Application.Min(rng.Cells(1).MergeArea.Width / shap.Width, rng.Cells(1).MergeArea.Height / shap.Height)
With shap
.LockAspectRatio = True
.Width = .Width * (Ratio * ((100 - marge) / 100))
.Top = rng.Top + ((rng.Cells(1).MergeArea.Height - .Height) / 2)
.Left = rng.Left + ((rng.Cells(1).MergeArea.Width - .Width) / 2)
End With
End Sub