Fra*_*ank 9 excel vba image excel-vba
我有一个包含大量文章编号的excel列表,例如."23378847".我希望列表中存储的所有文章编号的图片都存储在我的文件夹中.
但结果将如下.它应该是23378847.jpg而不是152499
http://media.byggtjeneste.no/media/bilde/152499/LargeThumbnail
或
http://www.nobb.no/Nobbnr/OrginalBilde/23378847/152499
有没有办法让我可以制作阅读我文件的文章,并使用与列表中相同的文章编号保存图片?
Sid*_*out 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
Run Code Online (Sandbox Code Playgroud)