|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
我原来的设想是从这个网址(https://www.hongkongairport.com/ ... e/fact-figures.page)上打开相应的PDF文档,并且也写好了代码,但公司的浏览器有时候不好使,打开不了PDF,所以想将PDF保存到指定位置。我之前的代码是照猫画虎写的,对InternetExplorer.Application并不是太熟,所以请大神帮忙修改一下。
- Option Explicit
- Sub GetHKPDF()
- Dim IE As Object
- Dim strUrl As String
- Set IE = CreateObject("internetExplorer.Application")
- With IE
- .Visible = False
- .navigate "https://www.hongkongairport.com/en/the-airport/hkia-at-a-glance/fact-figures.page"
- Application.StatusBar = "The webpage is loading, please wait..."
- Do While .readystate <> 4
- DoEvents
- Loop
- End With
- Application.StatusBar = "The webpage is fully loaded."
-
- 'construct the string of PDF with input from the user
- Dim PDFname As String
- PDFname = "/iwov-resources/file/the-airport/hkia-at-a-glance/facts-figures/"
- PDFname = PDFname & Cells(1, 1)
- PDFname = PDFname & "e.pdf"
- Debug.Print PDFname
-
- 'looking for the PDF,when the hyperlink contains the PDF name, click the link
- 'to open it
-
- Dim strFound As Boolean
- Dim aTag As Variant
- strFound = False
-
- For Each aTag In IE.document.GetElementsBytagName("a")
- If aTag.getattribute("href") = PDFname Then
- aTag.Click
- strFound = True
- Exit For
- End If
- Next
-
- 'Notify the user that the PDF is not found.
- If strFound = False Then
- MsgBox "HongKong AA has not yet published the statistics.Please try it later."
- End If
-
- Set IE = Nothing
- Application.StatusBar = False
-
- End Sub
复制代码
|
|