Importing Image into Excel Worksheet With HTML Code Elements

sopa12

New Member
Joined
Mar 30, 2019
Messages
4
Hello,

I'm looking to import a few images into my excel file and I plan on importing the picture by calling the pictures based on their html elements.

The image html code:
HTML:
<img chart-id="2669" alt="Chart ID 2669" class="chart-img" src="https://website.com/569134694870.jpg" diagnostic-id="chart-img-1" style="max-height: 150px;">

My code:

VBA Code:
Sub tt()
Dim strURL As String
Dim ie As Object
Dim Elem
Dim X

Set ie = CreateObject("InternetExplorer.Application")
strURL = "https://website.com/chartbooks/22920"
ie.navigate strURL
ie.Visible = True
Do While (ie.Busy Or ie.readyState <> 4)
    DoEvents
Loop

For Each Elem In ie.document.getElementsByTagName("img")
If ie.document.getElementsByTagName("img").getAttribute("alt") = "Chart ID 2669" Then
Worksheets("Sheet1").Range("A1") = ie.document.getElementsByTagName("img").getAttribute("src")

Exit For
End If
Next


End Sub

The current code errors out at
VBA Code:
If ie.document.getElementsByTagName("img").getAttribute("alt") = "Chart ID 2669" Then

The error message says the Object doesn't support this property or method. Any ideas on how to resolve this? Much appreciated.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Hi this is because " The page you are looking for might have been removed, had its name changed, or is temporarily unavailable. "
 
Upvote 0
Hi this is because " The page you are looking for might have been removed, had its name changed, or is temporarily unavailable. "
I'm sorry, I'm not sure I understand what you mean? The page is not removed I changed the url name because the website is a subscription website.
 
Upvote 0
Good Day
Try this no Error but still wepPage not exists from my side
VBA Code:
Sub tt()
Dim strURL As String
Dim ie As Object
Dim Elem
Dim X

Set ie = CreateObject("InternetExplorer.Application")
strURL = "https://website.com/chartbooks/22920"
ie.navigate strURL
ie.Visible = True
Do While (ie.Busy Or ie.readyState <> 4)
    DoEvents
Loop

For Each Elem In ie.document.getElementsByTagName("img")
If Elem.getAttribute("alt") = "Chart ID 2669" Then
Worksheets("Sheet1").Range("A1") = Elem.getAttribute("src")

Exit For
End If
Next


End Sub
 

Attachments

  • Http404.gif
    Http404.gif
    13.1 KB · Views: 30
Upvote 0

Forum statistics

Threads
1,223,887
Messages
6,175,199
Members
452,617
Latest member
Narendra Babu D

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top