I am using the following VBA Function in Access 2010 to download a file from the Internet. This Function will be used to distribute a new Access Front-End application connected to MySQL Back-End server.
My question ... Is there any modification to the code below that would force it to download the file from the url link instead of using the Cached folder on the local machine????
Public 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
Function DownloadFile()
On Error GoTo err_1
Dim lngPCallerParam As Long
Dim strURLParam As String
Dim strFilenameParam As String
Dim returnValue As Long
On Error GoTo err_1
strURLParam = 'http://www.somedomain.com/appfolder/MyApp.accdb'
strFilenameParam = 'C:TempMyApp.accdb'
returnValue = URLDownloadToFile(0, strURLParam, strFilenameParam, 0, 0)
Err_Exit:
Exit Function
err_1:
MsgBox Err.Description
Resume Err_Exit
End Function
Thanks,
ET
Thank you very much poorhall for your reply, your link sound some intresting will need to get on that more details till i get it work, anyhow if you talk from working with IE, i did setup a while ago an IE automation to log-in to that website, but how do i download a file what code should i use for that? Note that if you try to download large files, or your internet connection is slow the workbook, it might take some time to complete the download. However, in any case, the message box at the end of the procedure will inform you that the downloading has finished. Running Access Queries From Excel Using VBA. Excel & VBA: Download Internet.
The problem with the code below is, once the file has been downloaded on the remote machine it will remain in cached. Therefore, when the next update is published, it will now be downloaded. It is being pulled from the Cached folder on the local machine. A workaround is to add a unique id at the end of the file name like 'http://www.somedomain.com/appfolder/MyApp.accdbmm-dd-yyyy-hh-nn-ss' to make it unique each time.My question ... Is there any modification to the code below that would force it to download the file from the url link instead of using the Cached folder on the local machine????
Public 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
Function DownloadFile()
On Error GoTo err_1
Dim lngPCallerParam As Long
Dim strURLParam As String
![Vba Access Download File From Internet Vba Access Download File From Internet](https://www.automateexcel.com/excel/wp-content/uploads/2019/06/vba-selenium-web-automation.png)
Dim returnValue As Long
On Error GoTo err_1
strURLParam = 'http://www.somedomain.com/appfolder/MyApp.accdb'
returnValue = URLDownloadToFile(0, strURLParam, strFilenameParam, 0, 0)
Err_Exit:
Exit Function
err_1:
MsgBox Err.Description
Resume Err_Exit
End Function
Thanks,
ET
- Points
- 50
- Posts
- 6
Hello,I've been spending the last few hours trying to figure out how to save a file onto the computer using VBA. The code template below that I found on another forum seems promising, except when I go to the desktop to access it, the .csv file has what looks like the page's source code instead of the actual file I want. This may be because when I go to the url, it doesn't automatically download the file; rather, I am asked to save the file to a certain location (since I don't know the path name of the uploaded file on the site).
Is there any way to alter this code to accommodate this, or will I have to use a different code entirely? Thanks!- [/COLOR]Sub Test() Dim FileNum As Long Dim FileData() As Byte Dim MyFile As String Dim WHTTP As Object On Error Resume Next Set WHTTP = CreateObject('WinHTTP.WinHTTPrequest.5') If Err.Number <> 0 Then Set WHTTP = CreateObject('WinHTTP.WinHTTPrequest.5.1') End If On Error GoTo 0 MyFile = 'MY_URL_HERE' WHTTP.Open 'GET', MyFile, False WHTTP.send FileData = WHTTP.responseBody Set WHTTP = Nothing If Dir('C:UsersBLAHBLAHDesktop', vbDirectory) = Empty Then MkDir 'C:UsersBLAHBLAHDesktop' FileNum = FreeFile Open 'C:UsersBLAHBLAHDesktopmemberdatabase.csv' For Binary Access Write As #FileNum Put #FileNum, 1, FileData Close #FileNum End Sub[COLOR=#333333]
Other forums with post:
[/COLOR]http://www.excelforum.com/exce…tml?p=3250234#post3250234
http://stackoverflow.com/quest…#comment24055014_16704938- Navigation
- OzGrid
- Forum
- Members
- Options
- Current Location
This site uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.Your browser has JavaScript disabled. If you would like to use all features of this site, it is mandatory to enable JavaScript.