2
I am trying to paste image (thumbnail) linked to a link as below:
Ex. The main website is: http://www.imdb.com/title/tt0071007/? ref_=nv_sr_7
From this main page, I intend to copy and paste as bitmap in Excel the image in the link: www.imdb.com/name/nm0001271/? ref_=tt_cl_i1.
See the VBA code I tried, but it doesn’t work:
Sub obter_imagem()
Dim v As Variant
Set ie = CreateObject("InternetExplorer.Application")
With ie
.Visible = True
.Navigate "http://www.imdb.com/title/tt0071007/?ref_=nv_sr_7"
esperar = Now + TimeValue("0:00:30")
Do Until (.Busy = False And .ReadyState = 4) Or esperar < Now: DoEvents: Loop
x = 0
Do Until x >= 500
Set foto = ie.Document.getelementsbytagname("A")(x)
If foto Like "*cl_i1" Then
foto.Select
.Selection.Copy
Sheets("FIGURAS").Select
Range("A1").Select
ActiveSheet.Paste
ActiveSheet.PasteSpecial Format:="Bitmap", link:=False, _ DisplayAsIcon:=False
Exit Do
End If
x = x + 1
Loop
End With
End Sub
I manually tested the link in which your code navigates, but it returns a blank page (only with the header, without any photo). Maybe your link is the problem. Copy and paste it into your browser for you to see. If you want to expand your knowledge, it is faster, more efficient and more reliable to get data through an HTTP request. link a boy made a code exactly to get an image of a web page using an HTTP request.
– Rodrigo Sassaki