excel,vba,下载c列图片链接,放置于excel同文件夹下的以a列为名称的文件夹下,以b列为图片名称

2025-04-06 11:29:38
推荐回答(1个)
回答1:

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 DownLoadPicture()
    myPath = ThisWorkbook.Path
    i = 1
    Do Until Cells(i + 1, 1) = ""
        myFolder = myPath & "\" & Cells(i, 1)
        fileName = Cells(i, 2) & ".jpg"
        fileLink = Cells(i, 3)
        MkDir myFolder
        If URLDownloadToFile(0&, fileLink, myFolder & "\" & fileName, 0&, 0&) = 0 Then
        Else
            MsgBox "Failure"
        End If
        i = i + 1
    Loop
End Sub

 注:如果是64位系统,要在第一行的Declare后面加上PtrSafe,即....Declare PtrSafe Function....