Sub Recup_Images_SharePoint()
Dim Feuille As Worksheet
Dim Der_Ligne As Long, i As Long
Dim URL_SharePoint As String
Dim Image As Shape
Dim Cell_Desti As Range
Set Feuille = ThisWorkbook.ActiveSheet
' Supprime les anciennes images de la colonne B
For Each Image In Feuille.Shapes
If Not Intersect(Image.TopLeftCell, Feuille.Columns("B")) Is Nothing Then
Image.Delete
End If
Next Image
Der_Ligne = Feuille.Cells(Feuille.Rows.Count, "A").End(xlUp).Row
For i = 2 To Der_Ligne
URL_SharePoint = Feuille.Cells(i, 1).Value
Set Cell_Desti = Feuille.Cells(i, 2)
If URL_SharePoint <> "" Then
With Feuille.Shapes
Set Image = .AddPicture(Filename:=URL_SharePoint, _
LinkToFile:=False, _
SaveWithDocument:=True, _
Left:=Cell_Desti.Left + 2, _
Top:=Cell_Desti.Top + 2, _
Width:=-1, _
Height:=-1)
End With
' Ajustement de l'image à la taille de la cellule
With Image
.LockAspectRatio = msoTrue
.Width = Cell_Desti.Width - 4
If .Height > Cell_Desti.Height Then
.Height = Cell_Desti.Height - 4
End If
' centrage
.Left = Cell_Desti.Left + (Cell_Desti.Width - .Width) / 2
.Top = Cell_Desti.Top + (Cell_Desti.Height - .Height) / 2
End With
End If
Set Image = Nothing
Next i
MsgBox "C'est fait (...ou pas)"
End Sub