[vba] WinHttp 파일 다운로드

하나를하더라도최선을 2020-04-10 01:02:26 30,546 0 0
Sub program1472_com()
 
    Dim B() As Byte, FN As Long
    Dim URL As String
    Dim filePath As String, FileName As String
    Dim C As Range
    filePath = ThisWorkbook.Path & "\/"
    
    For Each C In Range("A2:A100")
        If InStr(C, "http"= 1 Then
            URL = C.Value
            FileName = Split(URL, "/")(UBound(Split(URL, "/")))
            With CreateObject("WinHTTP.WinHTTPrequest.5.1")
                .Open "GET", URL, False
                .Send
                .WaitForResponse: DoEvents
                '// debug.? .GetAllResponseHeaders
                B = .ResponseBody
            End With
            FN = FreeFile
            Open filePath + FileName For Binary Access Write As #FN
                Put #FN, 1, B
            Close #FN
        End If
    Next
    MsgBox "모든 작업이 완료되었씁니다."
 
End Sub
 

댓글 0개

첫 번째 댓글을 작성해보세요!