从URL获取图片,然后重命名图片 [英] GET pictures from a url and then rename the picture

查看:248
本文介绍了从URL获取图片,然后重命名图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有很多文章编号的excel列表,例如。 23378847。而且我想要在我的文件夹中存储的列表中的所有文章编号的图片。



但结果将如下。它应该是23378847.jpg不是152499



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



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


解决方案

有没有办法让我阅读我的文件, / div>

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



我假设您的Excel文件将如下所示。请修改适用的代码。



  Option Explicit 

私有声明函数URLDownloadToFile Liburlmon_
别名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

'~~>这是保存图像的地方。根据需要更改
Const FolderName As String =C:\Temp\

子样本()
Dim ws As Worksheet
Dim LastRow As Long,我As Long
Dim strPath As String

'~~>列表的名称
设置ws =表(Sheet1)

LastRow = ws.Range(A& Rows.Count).End(xlUp)。行

对于i = 2 To LastRow'<〜〜2,因为第1行有头
strPath = FolderName& ws.Range(A& i).Value& .jpg

Ret = URLDownloadToFile(0,ws.Range(B& i).Value,strPath,0,0)

如果Ret = 0然后
ws.Range(C& i).Value =文件已成功下载
Else
ws.Range(C& i).Value =无法下载文件
End If
Next i
End Sub


I have a excel list with a lot of article numbers, eg. "23378847". And I want the pictures of all my article numbers in the list stored in my folder.

But the result will be as under. It should be 23378847.jpg not 152499

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

Is there a way that I can make a scrips that read my file and save the pic with the same article number as in the list?

解决方案

Here is a sample which will help you.

I am assuming that your Excel file will look like this. Please amend the code as applicable.

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

这篇关于从URL获取图片,然后重命名图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆