1

I have word document containing hyperlinked text. I want to go to that page and check if there is any embedded pdf. If there is I want to download the PDF

Hyperlink looks like this

http://pdfaiw.uspto.gov/.aiw?PageNum=0&docid=20150299141&homeurl=http\appft.uspto.gov

Most of the time link contains

<embed src="http://pimg-faiw.uspto.gov/fdd/41/2015/91/029/0.pdf"
       width="100%" height="850" type=application/pdf></embed>

Is there any way? I am completely novice in VBA.

Rahul
  • 10,830
  • 4
  • 53
  • 88
  • Take a look at this post: http://stackoverflow.com/questions/17877389/how-do-i-download-a-file-using-vba-without-internet-explorer – Hugues Paquet Blanchette Nov 04 '15 at 14:00
  • 1
    Thaks @HuguesPaquetBlanchette. Problem is My link is not directly downloading the file. I need to crawl withing HTML to find link to PDF. – Rahul Nov 05 '15 at 05:22
  • XMLHTTP object will give you all http codes inside web page, where you can find link to the file and download it. Inside the response, after dynamically calling url,you can search for " – Hugues Paquet Blanchette Nov 05 '15 at 13:32
  • 1
    @HuguesPaquetBlanchette: I am new to Programming. I will try and post the answer if succed. Thanks for your help. – Rahul Nov 06 '15 at 11:03

1 Answers1

0

This worked finally.

HttpReq.Open "GET", myURL, False
HttpReq.send
StrTxt = HttpReq.responseText
i = InStr(StrTxt, "http://pimg-faiw.uspto.gov/fdd")
If i > 0 Then
StrTxt = Mid(StrTxt, i, Len(StrTxt) - i)
i = InStr(StrTxt, ".pdf")
If i > 0 Then
myURL = Left(StrTxt, i + 3)
WinHttpReq.Open "GET", myURL, False
WinHttpReq.send
myURL = WinHttpReq.responseBody
If WinHttpReq.Status = 200 Then
    Set oStream = CreateObject("ADODB.Stream")
    oStream.Open
    oStream.Type = 1
    oStream.Write WinHttpReq.responseBody
    oStream.SaveToFile "C:\file.Pdf", 2
    oStream.Close
End If
Rahul
  • 10,830
  • 4
  • 53
  • 88