从url获取图片,然后重命名图片

我有很多文章编号的excel列表,例如。 “23378847”。 我想要列表中存储在我的文件夹中的所有商品编号的图片。

但结果会是如此。 应该是23378847.jpg而不是152499

http://media.byggtjeneste.no/media/bilde/152499/LargeThumbnail
要么
http://www.nobb.no/Nobbnr/OrginalBilde/23378847/152499

有没有办法,我可以做一个脚本读取我的文件,并保存与列表中相同的文章编号的图片?

这是一个可以帮助你的样本。

我假设你的Excel文件看起来像这样。 请修改适用的代码。

在这里输入图像说明

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 Dim Ret As Long '~~> This is where the images will be saved. Change as applicable Const FolderName As String = "C:\Temp\" Sub Sample() Dim ws As Worksheet Dim LastRow As Long, i As Long Dim strPath As String '~~> Name of the sheet which has the list Set ws = Sheets("Sheet1") LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row For i = 2 To LastRow '<~~ 2 because row 1 has headers strPath = FolderName & ws.Range("A" & i).Value & ".jpg" Ret = URLDownloadToFile(0, ws.Range("B" & i).Value, strPath, 0, 0) If Ret = 0 Then ws.Range("C" & i).Value = "File successfully downloaded" Else ws.Range("C" & i).Value = "Unable to download the file" End If Next i End Sub