Debug.Prints nothing...
Results 1 to 4 of 4

Thread: Debug.Prints nothing...
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Oct 2007
    Posts
    709
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Debug.Prints nothing...

    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/DIS1...81123C00101000


    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
    The trick with sneaky users is not teaching them anything lest they get wise!

  2. #2
    MrExcel MVP Rick Rothstein's Avatar
    Join Date
    Apr 2011
    Location
    New Jersey, USA
    Posts
    34,958
    Post Thanks / Like
    Mentioned
    91 Post(s)
    Tagged
    33 Thread(s)

    Default Re: Debug.Prints nothing...

    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)?
    Rick's "mini" blog... http://www.excelfox.com/forum/f22/
    .
    Want to post a small screen shot? See Part B here.

  3. #3
    Board Regular
    Join Date
    Mar 2014
    Posts
    2,376
    Post Thanks / Like
    Mentioned
    10 Post(s)
    Tagged
    1 Thread(s)

    Default Re: Debug.Prints nothing...

    Quote Originally Posted by Rick Rothstein View Post
    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.

  4. #4
    Board Regular
    Join Date
    Jan 2014
    Location
    Dublin, Ireland
    Posts
    1,421
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Debug.Prints nothing...

    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
    Learn something new everyday.

    be sure to use code tags

    Code:
    [ code ]
    [ / code ]
    ' no spaces

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •