excel vba下载超链接图片

excel的sheet1中有若干小图片,每个小图片都有一个http的链接,如何通过点击或者其它的操作把图片下载下来?由于图片太多了,有几千张,所以需要vba操作,普通的把超链接复制出来,用下载工具下载太慢了。

可以用vba代码完成:
1、先编制表格:

2、在表格里编写触发宏代码:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim photoname As String

If Target.Row = 3 And Target.Column > 3 And Target.Column < 6 Then
On Error Resume Next '忽略错误继续执行VBA代码,避免出现错误消息
Application.ScreenUpdating = False
Application.EnableEvents = False
For Each shp In Sheets("查询表").Shapes
If shp.Type <> 8 And shp.Type <> 12 Then
shp.Delete
End If
Next
photoname = Cells(3, 4) & ".JPG"
Cells(3, "L").Select
ActiveSheet.Pictures.Insert(ActiveWorkbook.Path & "\照片\" & photoname).Select '当前文件所在目录下以单元内容为名称的.jpg图片
With Selection
ta = Range(Cells(3, "L").MergeArea.Address).Height '单元高度
tb = Range(Cells(3, "L").MergeArea.Address).Width '单元宽度
tc = .Height '图片高度
td = .Width '图片宽度
tm = Application.WorksheetFunction.Min(ta / tc, tb / td) '单元与图片之间长宽差异比例的最小值
.Top = ActiveCell.Top + 2
.Left = ActiveCell.Left + 1
.Height = .Height * tm * 0.98 '按比例调整图片宽度
.Width = .Width * tm * 0.98 '按比例调整图片高度
End With
Cells(3, 4).Select
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
3、在当前目录下建个名为”照片“的子目录,里面存有以姓名为名称的.jpg格式的照片

4、在姓名后单元输入姓名后,就能自动插入图片了
温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-08-09
上传文件或留下你的QQ,我来试一下
相似回答