9

我有一个包含很多文章编号的 Excel 列表,例如。“23378847”。我希望将列表中所有文章编号的图片存储在我的文件夹中。

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

http://media.byggtjeneste.no/media/bilde/152499/LargeThumbnail

http://www.nobb.no/Nobbnr/OrginalBilde/23378847/152499

有没有办法让我制作一个脚本来读取我的文件并使用与列表中相同的文章编号保存图片?

4

2 回答 2

24

这是一个可以帮助您的示例。

我假设您的 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
于 2012-04-30T15:38:28.860 回答
3

对于那些不想处理 VBA 或任何其他编程语言的人来说,有一个桌面 Web 应用程序让它变得超级简单。

只需放入excel文件,它会将excel文件中的所有图像(或文件)下载到您选择的文件夹中,如果B列上有名称,它也会重命名文件。

最新版本可以在https://github.com/btargac/excel-parser-processor上找到。

于 2020-10-18T10:28:11.697 回答