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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
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,215,417
Messages
6,124,783
Members
449,188
Latest member
Hoffk036

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