Option Explicit
Sub AjusterImages()
Dim Img As Excel.Picture
For Each Img In ActiveSheet.Pictures
AjusteImage Img: Next Img
End Sub
Sub DéplacImage1()
If Not TypeOf Selection Is Excel.Picture Then
If MsgBox("Veuillez sélectionner une image", vbOKCancel, "DéplacImage1") _
= vbOK Then Application.OnTime Now + TimeSerial(0, 0, 3), "DéplacImage1"
Exit Sub: End If
AjusteImage Selection
End Sub
Sub AjusteImage(ByVal Img As Excel.Picture)
Dim PosImg As Integer, NbImg As Integer, Gauche As Double, _
Largeur As Double, Dessus As Double, Bas As Double
NbImg = ActiveSheet.[G1].Value
With ActiveSheet.[B2:B6]: Gauche = .Left: Largeur = .Width
Dessus = .Top: Bas = Dessus + .Height: End With
PosImg = Int(IntpoLin(Img.Top + Img.Height / 2, Dessus, 0.5, Bas, NbImg + 0.5) + 0.5)
Img.Top = IntpoLin(PosImg, 0.5, Dessus, NbImg + 0.5, Bas) - Img.Height / 2
Img.Left = Gauche + (Largeur - Img.Width) / 2
End Sub
Function IntpoLin(ByVal X As Double, ByVal X1 As Double, ByVal Y1 As Double, _
ByVal X2 As Double, ByVal Y2 As Double) As Double
IntpoLin = Y1 + (Y2 - Y1) * (X - X1) / (X2 - X1)
End Function