【Excel-VBA】画像URLからサムネイルをエクセルシートに張り付ける

Function URLPictureInsert() ‘画像インポート 画像アドレスが必要

Dim Pshp As Shape
Dim xRg As Range
Dim xCol As Long
On Error Resume Next

Dim sh01 As Worksheet
Set sh01 = Worksheets(“キーワード一覧”)

‘Application.ScreenUpdating = False

row01 = sh01.Cells(Rows.Count, 1).End(xlUp).Row ‘最終行

Set Rng = sh01.Range(“E2:E” & row01)’ここに画像アドレスを入れる
For Each Cell In Rng
filenam = Cell
ActiveSheet.Pictures.Insert(filenam).Select
Set Pshp = Selection.ShapeRange.Item(1)
If Pshp Is Nothing Then GoTo lab
xCol = Cell.Column + 1
Set xRg = Cells(Cell.Row, xCol)
With Pshp
.LockAspectRatio = msoFalse
If .Width > xRg.Width Then .Width = xRg.Width * 2 / 3
If .Height > xRg.Height Then .Height = xRg.Height * 2 / 3
.Top = xRg.Top + (xRg.Height – .Height) / 2
.Left = xRg.Left + (xRg.Width – .Width) / 2
End With
lab:
Set Pshp = Nothing
Range(“A2”).Select
Next
‘Application.ScreenUpdating = True
End Function

コメントを残す

メールアドレスが公開されることはありません。