
我的任務是下載數百個 pdf 文件,這些文件透過超連結連結到一個巨大的 Excel 文件。現在,我單擊超鏈接,這會在 Internet Explorer 中的 adobe reader 中打開該文件,並將該文件保存到我的電腦上的資料夾中。有沒有一種方法可以點擊 Excel 中的超連結並“另存為”,而不必經歷逐一開啟和儲存每個 pdf 的繁瑣過程?如果這個問題看起來有點愚蠢或模糊,我很抱歉,我根本不懂技術!
答案1
我會帶你去那裡。沒有足夠的資訊來完成這一切,但查找其餘部分很容易。
這使用 vba 程式碼來執行您要求的操作。
下面是程式碼來自維巴快遞姆維達斯寫的。它需要一個互聯網地址並將其保存到本地文件中。
Option Explicit
Function SaveWebFile(ByVal vWebFile As String, ByVal vLocalFile As String) As Boolean
Dim oXMLHTTP As Object, i As Long, vFF As Long, oResp() As Byte
'You can also set a ref. to Microsoft XML, and Dim oXMLHTTP as MSXML2.XMLHTTP
Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP")
oXMLHTTP.Open "GET", vWebFile, False 'Open socket to get the website
oXMLHTTP.Send 'send request
'Wait for request to finish
Do While oXMLHTTP.readyState <> 4
DoEvents
Loop
oResp = oXMLHTTP.responseBody 'Returns the results as a byte array
'Create local file and save results to it
vFF = FreeFile
If Dir(vLocalFile) <> "" Then Kill vLocalFile
Open vLocalFile For Binary As #vFF
Put #vFF, , oResp
Close #vFF
'Clear memory
Set oXMLHTTP = Nothing
End Function
用於測試它的巨集
Sub TestingTheCode()
'This will save the Google logo to your hard drive, insert it into the
' active spreadsheet, then delete the local file
SaveWebFile "http://www.google.com/intl/en/images/logo.gif", "C:\GoogleLogo.gif"
ActiveSheet.Pictures.Insert "C:\GoogleLogo.gif"
Kill "C:\GoogleLogo.gif"
End Sub
使用此函數,您需要設定一個循環並從超連結中獲取地址
您需要設定一個循環來遍歷單元格,獲取超連結位址並運行該函數
For i = 1 to lastRow
cellAddress = Replace(Range("A" & i).Hyperlinks(1).Address, "mailto:", "")
'Something to get the file name from the whole file name here
SaveWebFile cellAddress, destinationFolder & filename
Next