Public Function ImgInsert(cel As Range, place As Range)
Dim X, ImG
If cel > 21 Then
Set ImG = ActiveSheet.Pictures.Insert("C:\Users\patricktoulon\Desktop\Rosee.png")
ImG.Name = "eclair"
X = Dimension_Position2(place, ActiveSheet.Shapes(ImG.Name), 100)
ImG.Left = X(0)
ImG.Top = X(1)
ImG.Width = X(2): ImG.Height = X(3)
Else
On Error Resume Next
ActiveSheet.Shapes("eclair").Delete
Err.Clear
End If
ImgInsert = ""
End Function
Function Dimension_Position2(rng As Range, shap, Optional marge As Double = 0)
DoEvents
Dim Wr#, Hr#, W#, H#, L#, T#, Ratio#
Ratio = Application.Min(rng.Width / shap.Width, rng.Height / shap.Height)
W = shap.Width: H = shap.Height
Wr = (W * Ratio) '* ((100 - marge) / 100)
Hr = (H * Ratio) '* ((100 - marge) / 100)
T = rng.Top + (rng.Height - Hr) / 2
L = rng.Left + (rng.Width - Wr) / 2
Dimension_Position2 = Array(L, T, Wr, Hr)
End Function