Forum Discussion
Convert image url to actual image in excel
You can update the code like the following by adding this line to it:
Pshp.Placement = xlMoveAndSize
Sub URLPictureInsert()
'Updateby Extendoffice 20161116
'Update #1 by Haytham Amairah in 20180104
'Update #2 by Haytham Amairah in 20180108
Dim Pshp As Shape
Dim xRg As Range
Dim xCol As Long
On Error Resume Next
Application.ScreenUpdating = False
Set Rng = ActiveSheet.Range("A2:A140")
For Each cell In Rng
filenam = cell
ActiveSheet.Pictures.Insert(filenam).Select
Set Pshp = Selection.ShapeRange.Item(1)
Pshp.Placement = xlMoveAndSize
If Pshp Is Nothing Then GoTo lab
xCol = cell.Column + 1
Set xRg = Cells(cell.Row, xCol)
With Pshp
.LockAspectRatio = msoFalse
.Width = 60
.Height = 30
.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
This will change the property for each image after inserting it to make it move and size with the cell.
Haytham Amairah Thank you for providing this.
I am running hte macro and stepping through.... each cell (Pshp) evaluates as empty and moves to the "lab" but there are clearly URLs in my range.
I can see filenam is set properly but Pshp is always nothing.
Any thoughts on why that would happen?
- Markus_SemmelmannFeb 11, 2020Copper Contributor
Hi,
i´ve tried your sample on excel for mac and nothing happend!
is it possible that these script won´t work on mac?
thank you
markus
- RobOKDec 16, 2019Bronze Contributor
Haytham Amairah it's not that important any more, but here it is...
- Haytham AmairahDec 15, 2019Silver Contributor
Hi,
We need to look into the range and the URLs to figure out the problem!
So, please provide the workbook or a dummy version of it.
Regards