[vb6.0/vba] vba 바탕화면의 특정폴더에 파일 다운로드 > vb6.0/vba

본문 바로가기

vb6.0/vba

[vb6.0/vba] [vb6.0/vba] vba 바탕화면의 특정폴더에 파일 다운로드

회원사진
하나를하더라도최선을
2020-03-16 23:05 3,363 0

본문



Sub download_Files_From_Web()
    Dim C As Range
    Dim strPath As String
    Dim filename As String
    strPath = CreateObject("WScript.Shell").SpecialFolders("Desktop"& "\ABC\"
    If Len(Dir(strPath, vbDirectory)) = 0 Then MkDir strPath
    If Len(Dir(strPath, vbDirectory)) = 0 Then
        MsgBox "폴더를 생성할 수 없습니다."
        End
    End If
    For Each C In ActiveSheet.UsedRange
        If InStr(C, "http"Then
            filename = C.Next & "." & Split(C, ".")(UBound(Split(C, ".")))
            DownloadFile C.Value, strPath, filename
        End If
    Next
    MsgBox "End."
End Sub
 
Function DownloadFile(url As String, DownloadPath As String, filename As String)
    Dim Buf() As Byte, FN As Integer
    DownloadPath = IIf(Right(DownloadPath, 1= "\", Left(DownloadPath, Len(DownloadPath) - 1), DownloadPath)
    DownloadPath = DownloadPath & "\" & filename
    With CreateObject("WinHttp.WinHttpRequest.5.1")
        .Open "GET", url, 0
        .send
        Buf = .responsebody
    End With
    FN = FreeFile()
    Open DownloadPath For Binary Access Write As #FN
        Put #FN, , Buf
    Close #FN
 End Function
 

댓글목록0

등록된 댓글이 없습니다.
게시판 전체검색