Getting text in <h1> tag

Mattestion

New Member
Joined
May 22, 2011
Messages
19
Hi. I'm using Excel 2007 on Vista SP2. I'm writing a sub to submit an address from Excel into Canada Post website to retrieve the postal code. For now I have hard-coded the address but I will change it to variables later. So far I have been able to enter the address, click the find button, and get the result page. The trouble I'm having is getting the postal code. When I look at the source, it is found in a tag. So I thought using getElementsByTagName would work but it doesn't (or at least the way I used it). I've also tried using body.innerText or body.innerHTML and then text extraction but couldn't do it. What do I need to do or am I trying to do something that can't be done? P.S. If anyone needs to see the web page source, just run the sub to get the results page then use your browser to view its source.

Here is my code so far:
Code:
Sub SEARCH()
    Dim ie As Object
    Set ie = CreateObject("internetexplorer.application")
    ie.Visible = True
    
    ie.navigate "http://www.canadapost.ca/cpotools/apps/fpc/personal/findByCity?execution=e1s1"
    
    Do
        If ie.readyState = 4 Then
            ie.Visible = False
            Exit Do
        Else
            DoEvents
        End If
    Loop
    ie.Visible = True
    
    ie.document.getElementById("fpcByAdvancedSearch:fpcSearch:streetNumber").Value = "2650"
    ie.document.getElementById("streetName").Value = "Thimens"
    ie.document.getElementById("city").Value = "Saint-Laurent"
    ie.document.getElementById("fpcByAdvancedSearch:fpcSearch:province").Value = "QC"
    
    Set tags = ie.document.getElementsByTagName("Input")

    For Each tagx In tags
        If tagx.alt = "Find" Then
            tagx.Click
        End If
    Next
    
    Do
        If ie.readyState = 4 Then
            ie.Visible = False
            Exit Do
        Else
            DoEvents
        End If
    Loop
    ie.Visible = True  
    
End Sub
 
Last edited:

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
For a button just add one from the Forms toolbar/Developer menu.

Then right click it, select Assign Macro... and pick the sub from the Macros dialog.
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,683
Members
452,938
Latest member
babeneker

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