Solved How can I directly access a pdf on an external server?

Dell / Inspiron one 2320
June 25, 2014 at 16:13:21
Specs: Windows 7 Home Premium, 3.3 GHz / 4001 MB
We all know that we can open a pdf from a link on a webpage or in a spreadsheet or some other document. When we click the link, the pdf opens a browser window and we can then (usually) save the pdf to a location of our choosing, such as our Documents folder, our Desktop, etc.

I'm looking for a way to directly access the file and save it to a specific location without having to go through the "open - click save - choose location" process.

For example, I can put this link in an Excel cell, click it to open the pdf and then click the Save icon to save a copy locally.

http://www.pdf995.com/samples/pdf.pdf

I know how to write VBA code to open workbooks on my system and save them where I want by including the path to the Save location in the code. I can also write code to follow the link in the cell and open the pdf.

What I don't know how to do is write VBA code to save the pdf found via the hyperlink without opening it, more like a direct download.

I guess the general question is this: Is it possible to access the file directly and Save it or does the server where the file is stored only accept requests via an hyperlink? Please note that I don't have any special permissions on the servers where the files are stored. The pdf's could be mutual fund fact sheets, appliance manuals, or any other pdf that is publicly available just by clicking a link. I just want to be able to save the pdf's that I have links to in a spreadsheet without opening them first.

Thanks!

message edited by DerbyDad03


See More: How can I directly access a pdf on an external server?

Report •


#1
June 25, 2014 at 16:46:24
You don't need VBA. This is easily done with either curl or wget.

wget man page
Download GnuWin tools which includes wget.


Report •

#2
June 25, 2014 at 16:55:18
Usage example.

First, a dir listing to show that I don't have the file.
C:\>dir pdf
Volume in drive C is OS
Volume Serial Number is C498-EE8A

Directory of C:\pdf

06/25/2014 04:34 PM <DIR> .
06/25/2014 04:34 PM <DIR> ..
0 File(s) 0 bytes
2 Dir(s) 16,698,400,768 bytes free


Now I'll use wget to download the file
C:\>wget -O c:/pdf/pdf.pdf http://www.pdf995.com/samples/pdf.pdf
SYSTEM_WGETRC = c:/progra~1/wget/etc/wgetrc
syswgetrc = C:\Program Files (x86)\GnuWin32/etc/wgetrc
--2014-06-25 16:36:12-- http://www.pdf995.com/samples/pdf.pdf
Resolving www.pdf995.com... 98.139.134.174
Connecting to www.pdf995.com|98.139.134.174|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 433994 (424K) [application/pdf]
Saving to: `c:/pdf/pdf.pdf'

100%[======================================>] 433,994 228K/s in 1.9s

2014-06-25 16:36:15 (228 KB/s) - `c:/pdf/pdf.pdf' saved [433994/433994]


Another dir listing
C:\>dir pdf
Volume in drive C is OS
Volume Serial Number is C498-EE8A

Directory of C:\pdf

06/25/2014 04:36 PM <DIR> .
06/25/2014 04:36 PM <DIR> ..
06/25/2014 04:36 PM 433,994 pdf.pdf
1 File(s) 433,994 bytes
2 Dir(s) 16,697,966,592 bytes free


Report •

#3
June 25, 2014 at 17:24:27
✔ Best Answer
Code's for VBScript, but it'll work in VBA all the same: http://serverfault.com/questions/29...

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
June 25, 2014 at 21:07:45
Thanks guys, I'll take at look at these suggestions.

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.


Report •

#5
June 26, 2014 at 06:03:21
Razor2.3, you da man!

I copied the code from that thread into the VBA editor. The compiler threw up a Syntax Error on this line:

   objXMLHTTP.send()

I took a shot and removed the parentheses and the code ran perfectly.

Now all I need to do is modify the code to pick up the server file location and the Save path/filename from the spreadsheet and I should be good to go.

I'm actually doing this to answer a question in the Office forum. Full credit will be given to you for the main solution. The "Excel" part of the solution is the easy part, the downloading of the file is where I needed help.

Thanks!

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.


Report •

#6
June 26, 2014 at 06:59:31
I'm not sure I should get full credit; all I did was google for "msxml.xmlhttp" and picked a code sample that was good enough.

How To Ask Questions The Smart Way


Report •

#7
June 26, 2014 at 11:35:40
re: msxml.xmlhttp

Isn't that the wierd little villian from the Superman comic? Oh, wait, that was Mister Mxyzptlk. ;-)

At least you knew what to google for. I wouldn't know a msxml.xmlhttp if it bit me in the arse.

OK, so I didn't give you full credit. In computing.net's Office forum, you were named directly. In another Excel forum, unrelated to computing.net, I simply said "someone" provided a link that led me to the final solution. I guess that's 50% credit.

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.


Report •

Ask Question