[go: up one dir, main page]

0% found this document useful (0 votes)
45 views1 page

Direct Insert Image From URL Into Excel

This macro inserts pictures from file names in a range into the active sheet and sizes and positions them within corresponding cells. It loops through a range, inserts each picture, sizes it to fit the cell if needed, and positions it centered within the cell.

Uploaded by

Ananth Huilgol
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views1 page

Direct Insert Image From URL Into Excel

This macro inserts pictures from file names in a range into the active sheet and sizes and positions them within corresponding cells. It loops through a range, inserts each picture, sizes it to fit the cell if needed, and positions it centered within the cell.

Uploaded by

Ananth Huilgol
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Sub URLPictureInsert()

Dim Pshp As Shape


Dim xRg As Range
Dim xCol As Long
On Error Resume Next
Application.ScreenUpdating = False
Set Rng = ActiveSheet.Range("A2:A5")
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 Sub

You might also like