Macro that downloads pdf file to designated folder from URL. Its very useful when you have a large number of pdf's you need to download from the internet.
- 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.
![Urldownloadtofile Urldownloadtofile](https://3.bp.blogspot.com/-0PFYD_EqADQ/VXNfiXfWz-I/AAAAAAAADYw/2NvYARBRAkc/s1600/Excel%2B%2526%2BVBA%2B-%2BDownload%2BInternet%2BFiles%2BAutomatically.jpg)
downloading files from a website
downloading files from a website
I periodically download (large) zip files from a website, and I would like to automate the process in VBA. The website url is of the form http://xxxxx/xxxx/xxxx.asp, and then I click on a link that displays a File Download window with Open, Save and Cancel buttons. I click on Save and save it to my C: drive. (When I hover over the link, it says the file name is of the form http://xxxxx/Datasets/xxx.zip).
I have added references for 'Microsoft Internet Controls' and 'Microsoft HTML Object Library', which let me create InternetExplorer and HTMLDocument objects. But I've never used these objects before and I don't know how to put the pieces together.
I'm using Access 2003.
Any help would be appreciated. Thanks
I have added references for 'Microsoft Internet Controls' and 'Microsoft HTML Object Library', which let me create InternetExplorer and HTMLDocument objects. But I've never used these objects before and I don't know how to put the pieces together.
I'm using Access 2003.
Any help would be appreciated. Thanks