I am not an expert in VBA by far so I was trying to get the answers from the posts here, however, I was not successful. I have checked here,here and in many other places but was not able to get the solution of the problem which is the following.
I would like to have the image pasted from a certain link in the adjacent or any other cell. The problem however is - it works for may websites, but it does not seem to work properly for amazon.
For example, this link:
https://images-eu.ssl-images-amazon.com/images/I/51GqMAG1MGL._SY300_QL70_ML3_.jpg
It works maybe once or twice, and then it stops for no apparent reason. And then it can grab the image again in say 2-3 hours? Mind you, the link is not dynamic.
In order for there not to raise any additional questions, I am trying to ease the job for our company by printing the image on the invoice for the warehouse use.
As such, I am grabbing (scraping) the link to the image in column I (there is a gap about 30 lines between the values) and then pasting it 3 cells to the left where the invoice is located.
The script I am using:
Sub URLPictureInsert()
Dim IMG As Shape
Dim xRg As Range
Dim xCol As Long
On Error Resume Next
Application.ScreenUpdating = False
Set rng = ActiveSheet.Range("I18:I2000")
For Each cell In rng
If cell <> "" Then
filenam = cell
ActiveSheet.Pictures.Insert(filenam).Select
Set IMG = Selection.ShapeRange.Item(1)
End If
If IMG Is Nothing Then GoTo lab
xCol = cell.Column - 2
Set xRg = Cells(cell.row, xCol)
With IMG
.LockAspectRatio = msoTrue
'If .Width > xRg.Width Then .Width = xRg.Width * 12 '/ 3
'If .Height > xRg.Height Then .Height = xRg.Height * 12 '/ 3
.Top = xRg.Top + (xRg.Height - .Height)
'.Top = Range("E10").Top
'.Left = Range("E10").Left
.Left = xRg.Left + (xRg.Width - .Width)
.Width = 150
.Height = 150
End With
lab:
Set IMG = Nothing
'Range("G15").Select
Next
Application.ScreenUpdating = True
End Sub
If any of you could be so kind to either modify this script or provide me with an alternative, I would sincerely appreciate it. If anything, running Office 365 64-bit.