VBA在Excel中如何保存http://blahblah.pdf网页作为pdf文件?

目前我的macros浏览IE浏览器下面的具体链接,并带我到一个点,我点击PDF链接,并在IE中打开它。

我现在想要做的是将这个打开的页面保存为pdf文件。 我已经尝试URLDownloadtofile保存文件,但不会允许我打开它。

这里是我的代码结束的示例:

Loop For Each e In ie.document.getElementsByTagName("span") If e.InnerText = "View Assigned Workout" Then e.ParentElement.Click Exit For End If Next Do While (ie.Busy Or ie.READYSTATE <> 4) DoEvents Loop Application.Wait (Now + TimeValue("0:00:1")) For Each e In ie.document.getElementsByTagName("strong") If e.InnerText = "View/Print Workout" Then e.ParentElement.Click Exit For End If Next Do While (ie.Busy Or ie.READYSTATE <> 4) DoEvents Loop For Each e In ie.document.getElementsByTagName("strong") If e.InnerText = "View Workout Card" Then e.ParentElement.Click Exit For End If Next Application.Wait (Now + TimeValue("0:00:1")) Do While (ie.Busy Or ie.READYSTATE <> 4) DoEvents Loop For Each e In ie.document.getElementsByTagName("strong") If e.InnerText = "Print" Then e.ParentElement.Click Exit For End If Next End Sub 

此时单击打印链接在IE中打开一个文件http://blahblah.pdf (无法访问实际的链接,因为需要login)

如何将这个文件保存为PDF到我桌面上的文件夹?

我尝试使用下面的代码:

 Option Explicit Private Declare Function URLDownloadToFile Lib "urlmon" Alias _ "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal _ szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long Sub Test() Dim strPDFLink As String Dim strPDFFile As String Dim Result As Boolean strPDFLink = "http://blahblah.pdf" strPDFFile = "savetestworkout.pdf" Result = DownloadFile(strPDFLink, strPDFFile) End Sub Function DownloadFile(URL As String, LocalFilename As String) As Boolean Dim lngRetVal As Long lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0) If lngRetVal = 0 Then DownloadFile = True End Function 

该文件被创build,但是当我尝试打开它时发生错误。 任何帮助将不胜感激。