|
- Sub getIMG()
- Dim imgURL$
- Dim XML As Object
- Dim cellNO As Integer
- Dim wj As String
- Dim rng As Range
- Dim picData() As Byte
-
- Dim picW As Single, picH As Single
- Dim cellW As Single, cellH As Single
- Dim rtoW As Single, rtoH As Single
- Set XML = CreateObject("msxml2.xmlhttp")
-
- Dim p As Integer
- For p = 2 To Application.CountA(Sheet6.Range("A:A"))
- imgURL = Sheet6.Cells(p, "E")
- Debug.Print imgURL, Application.CountA(Sheet5.Range("A:A"))
- Rem 下载图片,保存于工作薄同路径下,命名为temp1.jpg
- With XML
- .Open "GET", imgURL, False
- .send
- picData = .responsebody
- fp = ThisWorkbook.Path & "\temp1.jpg"
-
- Open fp For Binary Access Write As #1
- Put #1, 1, picData
- Close #1
- Sheet6.Cells(p, 8).Select
- Sheet6.Pictures.Insert(fp).Select
- Rem 自适应大小
- cellW = ActiveCell.Width
- cellH = ActiveCell.Height
- picW = Selection.ShapeRange.Width
- picH = Selection.ShapeRange.Height
- rtoW = cellW / picW * 0.99
- rtoH = cellH / picH * 0.99
- If rtoW < rtoH Then
- Selection.ShapeRange.ScaleWidth rtoW, msoFalse, msoScaleFromTopLeft
- Else
- Selection.ShapeRange.ScaleHeight rtoH, msoFalse, msoScaleFromTopLeft
- End If
- picW = Selection.ShapeRange.Width
- picH = Selection.ShapeRange.Height
- Selection.ShapeRange.IncrementLeft (cellW - picW) / 2
- Selection.ShapeRange.IncrementTop (cellH - picH) / 2
-
- End With
- Kill fp
- Next
- End Sub
- Sub DeletePic()
- Dim p As Shape
- For Each p In Sheet6.Shapes
- If p.Type = 11 Then
- p.Delete
- End If
- Next
- End Sub
复制代码
不好意思,打包错了 |
评分
-
1
查看全部评分
-
|