|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
试试:- 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
-
- Sub DownLoadPicture()
- Dim r, rr, url, Pn, Rng
- On Error Resume Next
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Call Delshp
- rr = [B65536].End(xlUp).Row
- For r = 2 To rr
- url = Range("B" & r).Value
- If url <> "" Then
- On Error Resume Next
- Pn = Split(url, "/")(UBound(Split(url, "/")))
- URLDownloadToFile 0, url, ThisWorkbook.Path & "" & Pn, 0, 0
- Set Rng = Range("C" & r) '设定插入目标图片的位置
- With ActiveSheet.Pictures.Insert(ThisWorkbook.Path & "" & Pn) '插入链接地址中的图片
- If .Height / .Width > Rng.Height / Rng.Width Then '判断图片纵横比与单元格纵横比的比值以确定针对单元格缩放的比例
- .Top = Rng.Top
- .Left = Rng.Left + (Rng.Width - .Width * Rng.Height / .Height) / 2
- .Width = .Width * Rng.Height / .Height
- .Height = Rng.Height
- Else
- .Left = Rng.Left
- .Top = Rng.Top + (Rng.Height - .Height * Rng.Width / .Width) / 2
- .Height = .Height * Rng.Width / .Width
- .Width = Rng.Width
- End If
- End With
- Kill ThisWorkbook.Path & "" & Pn
- End If
- Next
- Application.DisplayAlerts = True
- Application.ScreenUpdating = True
- MsgBox "OK,图片下载完成!"
- End Sub
- Sub Delshp()
- Application.DisplayAlerts = False
- On Error Resume Next
- Dim shp As Shape
- For Each shp In Worksheets("Sheet0").Shapes
- 'If shp.Type = msoPicture Then
- shp.Delete
- 'End If
- Next
- Application.DisplayAlerts = True
- End Sub
复制代码
|
|