
나는 거대한 Excel 파일의 하이퍼링크를 통해 연결된 수백 개의 PDF를 다운로드하는 임무를 맡고 있습니다. 지금은 인터넷 익스플로러의 Adobe Reader에서 파일을 여는 하이퍼링크를 클릭하고 내 컴퓨터의 폴더에 파일을 저장합니다. 각 PDF를 하나씩 열고 저장하는 지루한 과정을 거치는 대신 Excel에서 하이퍼링크를 클릭하고 "다른 이름으로 저장"할 수 있는 방법이 있습니까? 이 질문이 다소 어리석거나 모호해 보인다면 사과드립니다. 저는 기술에 전혀 정통하지 않습니다!
답변1
내가 거기까지 데려다줄게. 모든 작업을 수행하기에는 정보가 충분하지 않지만 나머지는 쉽게 찾아볼 수 있습니다.
이것은 vba 코드를 사용하여 요청한 작업을 수행합니다.
아래는vbaexpressMvidas가 작성했습니다. 인터넷 주소를 가져와 로컬 파일에 저장합니다.
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