1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| Sub test()
lienImage$ = "https://media.alinea.com/images/catalog/26501086/PIED-DE-LAMPE-METAL-CESARIO-26501086-A-1.jpg?v=2"
destination$ = Environ("userprofile") & "\DeskTop\" & "toto.jpg"
If telecharge_Image(lienImage, destination) = destination Then MsgBox "image telechargée"
End Sub
'
Function telecharge_Image(url As String, destination As String) As String
Dim ReQ As Object, oStream As Object
On Error Resume Next 'On ne gère pas les erreurs
Set ReQ = CreateObject("Microsoft.XMLHTTP")
ReQ.Open "get", url, False: ReQ.send
Set oStream = CreateObject("ADODB.Stream")
oStream.Open: oStream.Type = 1: oStream.Write ReQ.responsebody: oStream.SaveToFile destination$: oStream.Close
telecharge_Image = destination
Set oStream = Nothing: Set ReQ = Nothing
End Function |
Partager