Public Function DownloadHTTP(ByVal URL As String, ByVal Destination As String) As Boolean
On Error GoTo catch
Dim oWinHTTP As Object
Dim fic As Integer
Dim buffer() As Byte
Set oWinHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
oWinHTTP.Open "GET", URL, False
oWinHTTP.send
If oWinHTTP.Status = 200 Then
fic = FreeFile
Open Destination For Binary Lock Read Write As #fic
buffer = oWinHTTP.ResponseBody
Put #fic, , buffer
Close #fic
DownloadHTTP = True
Else
MsgBox "Statut retourné par le service : " & oWinHTTP.Status & vbCrLf & _
"Description : " & oWinHTTP.StatusText, vbExclamation, "DownloadHTTP()..."
End If
finally:
Erase buffer
Set oWinHTTP = Nothing
Exit Function
catch:
MsgBox "Erreur n°" & Err.Number & vbCrLf & "Description : " & Err.Description, vbExclamation, "DownloadHTTP()..."
Close 'ferme tous les descripteurs ouverts
Resume finally
End Function
Sub Test()
Debug.Print DownloadHTTP("http://qrickit.com/api/qr?d=Créer dynamiquement des QR Codes en image...&addtext=Test&txtcolor=fb660a&fgdcolor=fb660a&bgdcolor=000000&qrsize=300&t=p&e=m", ThisWorkbook.Path & "\QRCode.png")
End Sub