Debug.Prints nothing...

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
1,075
Office Version
  1. 2019
Platform
  1. Windows
I have watch many tutorials on this HTML subject, but I'm not understanding why this code is not working. I'm trying to get the Bid Price, and the code runs without error, but prints nothing. What am I doing wrong??? Very Frustrated!!! Please help. Thank you kindly.

the URL: https://finance.yahoo.com/quote/DIS181123C00101000?p=DIS181123C00101000


Code:
Sub GetRate()'*******************************************************************************
'Set references to:
'Microsoft Internet Controls
'Microsoft HTML Object Library
'Microsoft XML, v6.0
'Hit Alt+F11 to go to the Visual Basic Editor and then hit:
'Tools | References
'*******************************************************************************
    Dim XMLPage As New MSXML2.XMLHTTP60
    Dim htmlDoc As New MSHTML.HTMLDocument
    Dim URL As String
    Dim HTMLspans As MSHTML.IHTMLElementCollection
    Dim HTMLspan As MSHTML.IHTMLElement
    Dim titleElem As Object
    Dim topic As HTMLHtmlElement
    


    URL = "https://finance.yahoo.com/quote/DIS181123C00101000?p=DIS181123C00101000"
    
    XMLPage.Open "GET", URL, False
    XMLPage.send
    
    htmlDoc.body.innerHTML = XMLPage.responseText
    
    Set HTMLspans = htmlDoc.getElementsByTagName("Bxz(bb) Bdbw(1px) Bdbs(s) Bdc($c-fuji-grey-c) H(36px) ")
    
    For Each HTMLspan In HTMLspans
    
        If HTMLspan.className = "Ta(end) Fw(b) Lh(14px)" Then
            Debug.Print HTMLspan.innerText
        End If
    
    Next HTMLspan
    
End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
It would mean your If..Then test is failing. Perhaps what you think are normal spaces (ASCII 32) are really HTML non-breaking spaces (ASCII 160)?
 
Upvote 0
It would mean your If..Then test is failing. Perhaps what you think are normal spaces (ASCII 32) are really HTML non-breaking spaces (ASCII 160)?

Actually, when I single-step through it, it is the For Each that does nothing.

HTMLspans Is Nothing is False, but TypeName(HTMLspans.item) displays Nothing.

Honestly, I don't know enough about this to interpret what is going on. But hopefully someone like Rick can explain.
 
Upvote 0
your set should be to class name rather than tag name.

the below code gives an output of :

Previous Close16.17
Open16.17
Bid0.00
Ask0.00
Expire Date2018-11-23
Day's Range16.17 - 16.17
Contract RangeN/A
Volume1


A further if would give you the bid price only

Code:
Sub GetRate() '*******************************************************************************
'Set references to:
'Microsoft Internet Controls
'Microsoft HTML Object Library
'Microsoft XML, v6.0
'Hit Alt+F11 to go to the Visual Basic Editor and then hit:
'Tools | References
'*******************************************************************************
    Dim XMLPage As New MSXML2.XMLHTTP60
    Dim htmlDoc As New MSHTML.HTMLDocument
    Dim URL As String
    Dim HTMLspans As MSHTML.IHTMLElementCollection
    Dim HTMLspan As MSHTML.IHTMLElement
    Dim titleElem As Object
    Dim topic As HTMLHtmlElement
    




    URL = "https://finance.yahoo.com/quote/DIS181123C00101000?p=DIS181123C00101000"
    
    XMLPage.Open "GET", URL, False
    XMLPage.send
    
    htmlDoc.body.innerHTML = XMLPage.responseText
    
    Set HTMLspans = htmlDoc.getElementsByClassName("Bxz(bb) Bdbw(1px) Bdbs(s) Bdc($c-fuji-grey-c) H(36px) ")
    
    For Each HTMLspan In HTMLspans
    
        If HTMLspan.className = "Bxz(bb) Bdbw(1px) Bdbs(s) Bdc($c-fuji-grey-c) H(36px) " Then
            Debug.Print HTMLspan.innerText
        End If
    
    Next HTMLspan
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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