Forum Discussion
Convert image url to actual image in excel
I finally got it to work. I hadn't changed the insert cell location, just the url cell range.
Now I'm trying to figure out how to get the pics to scale with changing cell size. I've tried the following code https://www.extendoffice.com/documents/excel/4923-excel-picture-move-and-size-with-cells-default.html with no luck yet. Working with VBA is completely new to me. I appreciate your help and patience.
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.
- Gunhild_OterhalsAug 18, 2021Copper Contributor
This really made my day Haytham Amairah! 🙂 I was wondering if it's possible to add something to the VBA to append the url to the image as well? So the result is a image that you can click to view the original in browser?
- 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
- RobOKDec 14, 2019Bronze Contributor
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?