VBA, MS Access MS Access в примерах

Закачка файла по URL (API)

'--------------------------------------------------------------------
' Module    : modDownloadURL
' Author    : es
' Date      : 06.05.2013
' Purpose   : Закачка (загрузка) файла по URL (API)
'--------------------------------------------------------------------
Private Declare PtrSafe Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, _
    ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
'--------------------------------------------------------------------
Public Function URLDownLoadOneFile(sFileURL As String, sLocalFilePath As String) As Boolean
'Закачка файла по URL - При удаче возвращает = True
'--------------------------------------------------------------------
On Error GoTo URLDownLoadOneFile_Err
    URLDownLoadOneFile = URLDownloadToFile(0, sFileURL, sLocalFilePath, 0, 0) = 0
    
URLDownLoadOneFile_Bye:
    Exit Function

URLDownLoadOneFile_Err:
    'MsgBox "Error " & Err.Number & vbCrLf & Err.Description & vbCrLf & _
    "in procedure TestDownLoadOneFile", vbCritical, "Error!"
    Resume URLDownLoadOneFile_Bye
End Function



Пример эксплуатации:

Private Sub URLDownLoadTest()
    Debug.Print URLDownLoadOneFile("http://msa.polarcom.ru/st/s0000061_Connection_Example_v01.zip", _
    "D:\temp\Connection_Example_v01.zip")
End Sub
Назад ToTop
L.E. 28.10.2019
Рейтинг@Mail.ru