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:
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: