Extracting HTML/Javascript string values in VBA

Datanalysis

New Member
Joined
Feb 9, 2015
Messages
1
I am trying to pull the interest rates from the first table of the following page:
Bank Accounts | BMO Bank of Montreal

However, my code bellow isn't extracting the "0.80%" value and is only extracting "%". I think the values automatically update through javascript. Is there any way to extract this number through VBA?

Code:
Sub BMO()
    Dim Ptrtbl As Long, r As Long, c As Long
    Dim htm As Object
    Dim elemCollection, ratenum As Object


    Set htm = CreateObject("htmlFile")


    With CreateObject("msxml2.xmlhttp")
        .Open "GET", "http://www.bmo.com/home/personal/banking/rates/bank-accounts?pChannelId=0", False
        .Send
        htm.body.innerHTML = .responseText
    End With


    Set elemCollection = htm.getelementsbytagname("table")
    
    For Each itm In elemCollection
        If itm.Summary = "This table shows interest rates based on a paid balance for a smart saver account." Then
            
            Set ratenum = htm.getelementsbytagname("td")
            For Each num In ratenum
                
                 If num.classname = "rateCel" Then
         
                 'MsgBox (num.outerHTML)
                 ActiveCell = num.innerText


                    If ActiveCell.Column = 2 Then
                    ActiveCell.Offset(1, -1).Select
                    Else
                    ActiveCell.Offset(0, 1).Select
                    End If
                 End If
            Next
        End If
    Next
End Sub
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Because MSXML2 doesn't load/execute Javascript, try loading the page with IE:
Code:
    With CreateObject("InternetExplorer.Application")
        .Visible = True
        .Navigate "http://www.bmo.com/home/personal/banking/rates/bank-accounts?pChannelId=0"
        While .busy Or .readyState <> 4: DoEvents: Wend
        Set htm = .document
    End With
And the Set ratenum line should probably be:
Code:
Set ratenum = itm.getelementsbytagname("td")
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,885
Members
452,364
Latest member
springate

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