I am having problems running this code for displaying pictures in excel. I am a beginner, so I must be doing something wrong. When I run it I get the message "Run-time error '1004': Unable to get the Insert property of the Pictures class". When I depurate, excel marks this line that says: "With image_column.Worksheet.Pictures.Insert(url_column.Cells(i).Value)"
This is the code:
Sub pix()
Dim url_column As Range
Dim image_column As Range
Set url_column = Worksheets(1).UsedRange.Columns("A")
Set image_column = Worksheets(1).UsedRange.Columns("B")
Dim i As Long
For i = 1 To url_column.Cells.Count
With image_column.Worksheet.Pictures.Insert(url_column.Cells(i).Value)
.Left = image_column.Cells(i).Left
.Top = image_column.Cells(i).Top
image_column.Cells(i).EntireRow.RowHeight = .Height
End With
Next
End Sub
My excel file looks like this
\1
I have tried also another code for importing the pictures and display them. I created the folder IMAGENES EXCEL in C:
When I run it, I get the same error. and when I depurate I get this line marked: "With ActiveSheet.Pictures.Insert(PicPath & IconName & "1" & ".jpg")".
Sub Icon_Importer()
'
'
'
Dim PicPath As String
Dim IconName As String
PicPath = "C:\IMAGENES EXCEL\"
IconName = "Total"
For i = 1 To 3
With ActiveSheet.Pictures.Insert(PicPath & IconName & "1" & ".jpg")
With .ShapeRange
.LockAspectRatio = msoTrue
.Width = 25
.Height = 25
End With
.Left = ActiveSheet.Cells(4, 3 + i).Left
.Top = ActiveSheet.Cells(4, 3 + i).Top
.Placement = 1
.PrintObject = True
End With
Next i
End Sub
If anyone could help me I would be very grateful.
Bookmarks