【问题标题】:Download Embeded PDF file using VBA使用 VBA 下载嵌入式 PDF 文件
【发布时间】:2016-02-04 13:31:43
【问题描述】:

我有包含超链接文本的 word 文档。 我想去那个页面并检查是否有任何嵌入的 pdf。 如果有我想下载PDF

超链接看起来像这样

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

大部分时间链接包含

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

有什么办法吗? 我完全是 VBA 新手。

【问题讨论】:

  • 谢谢@HuguesPaquetBlanchette。问题是我的链接没有直接下载文件。我需要使用 HTML 抓取以找到指向 PDF 的链接。
  • XMLHTTP 对象将为您提供网页内的所有 http 代码,您可以在其中找到文件的链接并下载它。在响应中,动态调用url后,可以在字符串中搜索“
  • @HuguesPaquetBlanchette:我是编程新手。如果成功,我将尝试发布答案。感谢您的帮助。

标签: html vba winhttp


【解决方案1】:

终于成功了。

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

【讨论】:

  • 嗨,拉胡尔,我们能谈谈吗?联系我 9867711779
猜你喜欢
  • 2022-10-15
  • 1970-01-01
  • 2016-11-28
  • 1970-01-01
  • 2022-01-23
  • 2014-05-19
  • 2019-07-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多