从url vba下载图像

时间:2018-05-07 17:11:00

标签: excel vba excel-vba

我在A栏中有链接。我想从A栏的链接下载图片。

下面是适用于我的代码,但是已下载的文件不是JPG格式。我们能做些什么改变吗?另外,我们可以更改下载文件的文件夹吗?

Option Explicit

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 getJPGfromweb()
    Dim strJPGLink As String
    Dim strJPGFile As String
    Dim Result As Boolean
    strJPGLink = ActiveSheet.Range("A3").Value
    strJPGFile = ActiveSheet.Range("B1").Value
    Result = DownloadFile(strJPGLink, strJPGFile)
    MsgBox Result
End Sub

Function DownloadFile(URL As String, LocalFilename As String) As Boolean
    Dim lngRetVal As Long
    lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
    If lngRetVal = 0 Then DownloadFile = True
End Function

0 个答案:

没有答案