Downloading URL to SaveAs in Directory
Hi All,
I am trying to download about 250 hyperlinks to .pdfs. Obviously, this is a very tedious process if done manually so I am trying to automate it using VBA. I tried URLDownloadtofile but it doesn't correctly download the page so that I can open it. I think the reason with this has to do with the fact that the site has to authenticate. So, I've trying the XMLHTTP approach. I figured I'd first try to find some code that works for this purpose and then modify it to suit my needs. So far I have something that I found online (btw, couldn't use hyperlinks because I have fewer than 5 posts apparently) :
Sub Save()
SaveWebFile "I would have the hyperlink in here", "C:\blahblah"
End Sub
Function SaveWebFile(ByVal vWebFile As String, ByVal vLocalFile As String) As Boolean
Dim oXMLHTTP As Object, i As Long, vFF As Long, oResp() As Byte
Set oXMLHTTP = CreateObject("msxml2.xmlhttp")
oXMLHTTP.Open "GET", vWebFile, False
oXMLHTTP.send
oResp = oXMLHTTP.ResponseBody
vFF = FreeFile
If Dir(vLocalFile) <> "" Then Kill vLocalFile
Open vLocalFile For Binary As #vFF
Put #vFF, , oResp
Close #vFF
Set oXMLHTTP = Nothing
End Function
However, when I run it, I get the following error "Run-time error '75': Path/File access error. Can someone please explain why that is the case and what I can do to remedy the problem?
I guess, ultimately, I am not married to using the above process, but from what I understand it one of the ways to authenticate to a website, right? Thank you for your help!
Automating PDF Download and Save As from Authenticated Website
Quote:
Originally Posted by Kenneth Hobs
I don't see the purpose in downloading hyperlinks. Do you mean the address of a hyperlink? Is it an address in an Excel hyperlink or on the web site? Is the address a file such as
If it is a secure site, I don't see either method working. Obviously, the .ResponseBody would only return the html's body code in text format.
Until you get 5 posts, just breaks urls into words.
Here is an example of how I used urldownloadtofile.
You can attach an Excel file.
Hi Kenneth,
I was wondering if you had a chance to take a look at what I'm trying to do and why I am receiving the Cannot Access Path error I cited above. As I explained, I am ultimately trying to use VBA to download and save a PDF located at the end of a URL that needs authentication (Username and Password)to a specific file location. I have tried URLDownloadtofile (that fails because it won't authenticate websites and downloads corrupt/encrypted pdf files); I have tried the print as pdf way (but can't send sendkeys to the save as screen); I have tried the createObject("MSXML2.ServerXMLHTTP.6.0") method and that gives me errors... I know there is a way to do this but I just haven't been able to figure it out. Please can someone help me! Thank you in advance.
-V