1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| Private Sub EffacePhoto(rng As Range)
Dim Sh As Shape
For Each Sh In Sheets("vierge").Shapes
If Left(Sh.Name, 7) = "Img" & Format(rng.Row - 1, "00") & Format(rng.Column, "00") Then
Sh.Delete
Exit Sub
End If
Next Sh
End Sub
Private Function ExisteGIF(Image As String) As Boolean
Dim Tatiak As Object
Set Tatiak = CreateObject("Scripting.FileSystemObject")
ExisteGIF = Tatiak.FileExists(Image)
Set Tatiak = Nothing
End Function
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Image As String, LargeurImage As Single, Gauche As Single
Dim Sh As Shape, Tatiak As Object
Dim ImExt
Dim i As Byte
Dim OK As Boolean
ImExt = Array(".gif", ".bmp", ".jpg")
If InStr("F2|G2|H2", Target.Address(0, 0)) > 0 Then 'mettre ici toutes les adresses de tes listes
If Target.Value <> "" Then
Call EffacePhoto(Target)
For i = 0 To 3
Image = ThisWorkbook.Path & "\" & Target.Text & ImExt(i)
If ExisteGIF(Image) Then
OK = True
Exit For
End If
Next i
If OK Then
With Target.Offset(-1, 0)
Set Tatiak = ActiveSheet.Pictures.Insert(Image)
LargeurImage = (Tatiak.Width * .Height / Tatiak.Height) * 0.9
Tatiak.Delete
Set Tatiak = Nothing
Gauche = .Left + (.Offset(0, 1).Left - .Left - LargeurImage) / 2
Set Sh = ActiveSheet.Shapes.AddShape(msoShapeRectangle, Gauche, .Top, .Width, .Height)
'Le nom est désormais ImgXXYYzzzz, XX Ligne, YY colonne et zzzz valeur
Sh.Name = "Img" & Format(.Row, "00") & Format(.Column, "00") & .Value
Sh.Fill.UserPicture Image
Sh.Height = .Height * 0.9
Sh.Width = LargeurImage
Set Sh = Nothing
End With
End If
End If
End If
End Sub |
Partager