Debug.Prints nothing...

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
854
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
 

Some videos you may like

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
36,028
Office Version
2010
Platform
Windows
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)?
 

joeu2004

Well-known Member
Joined
Mar 2, 2014
Messages
2,744
Office Version
2010
Platform
Windows
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.
 

BarryL

Well-known Member
Joined
Jan 20, 2014
Messages
1,421
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
 

Watch MrExcel Video

Forum statistics

Threads
1,101,894
Messages
5,483,550
Members
407,397
Latest member
HerbA

This Week's Hot Topics

  • Finding issue in If elseif else with For each Loop
    Finding issue in If elseif else with For each Loop I have tried this below code but i'm getting in Y column filled with W005. Colud you please...
  • MsgBox Error
    Hi Guys, I have the below error show up when i try and run my macro in File1 but works fine if i copy and paste the same code into file2. [ATTACH...
  • CELL FORMAT - IF CONDITION
    My Cell Format is [B]""0.00" Cr". [/B]But in the cell, it is showing 123.00 for editing. (123 is entry figure). (Data imported from other...
  • Show numbers nearly the same
    Is this possible. I have a number that can change very time eg 0.00001234 Then I have a lot of numbers 0.0000001, 0.0000002, 0.00000004...
  • Please i need your help to create formula
    I need a formula in cell B8 to do this >>if b1=1 then multiply ( cell b8) by 10% ,if b1=2 multiply by 20%,if=3 multiply by 30%. Thank you in...
  • Got error while adding column and filter
    Got error while adding column and filter In column Z has some like "Success" and "Error". I want to add column in AA if the Z cell value is...
Top