How to download a file with VBA (1 Viewer)

CosmaL

Registered User.
Local time
Today, 16:32
Joined
Jan 14, 2010
Messages
93
Hi everyone!

I have an issue:

I get data from an online form via excel (linked table), which i append in my main table in access.
Each record has a field with an attachment, which i get as text/hyperlink in my linked table.

Is there a way to download the file and save it in a local folder?

Thanks in advance!
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 21:32
Joined
May 7, 2009
Messages
19,293
you can use API (from api - How do I download a file using VBA (without Internet Explorer) - Stack Overflow)
Code:
#If VBA7 Then
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
#Else
Declare 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
#End If


Sub Example()
    DownloadFile$ = "someFile.ext" 'here the name with extension
    URL$ = "http://some.web.address/" & DownloadFile 'Here is the web address
    LocalFilename$ = "C:\Some\Path" & DownloadFile !OR! CurrentProject.Path & "\" & DownloadFile 'here the drive and download directory
    MsgBox "Download Status : " & URLDownloadToFile(0, URL, LocalFilename, 0, 0) = 0
End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:32
Joined
Oct 29, 2018
Messages
21,694
Take a look at this article for more info.
 

Users who are viewing this thread

Top Bottom