9

多くの記事番号を含むExcelリストがあります。「23378847」。そして、フォルダーに保存されているリスト内のすべての記事番号の写真が必要です。

しかし、結果は以下のようになります。152499 ではなく 23378847.jpg にする必要があります

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 に答える