Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Request for Postal Codes


This request disappeared from the postings. do'nt know why. Here is the
solution

Sub Private Commandbutton1_Click()

Postcode = InputBox("Enter PostCode: ")

Postcode2 = InputBox("Enter 2nd PostCode: ")


Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True

URL = _
"http://www.postcode.org.uk/country/uk/_postcode-distance-calculator.asp"
IE.Navigate2 URL

Do While IE.readyState < 4 Or IE.busy = True
DoEvents
Loop

Set MyForm = IE.document.getElementsByTagname("Form")
Set inputform = MyForm.Item(0)

Set Postcodebox = inputform.Item(0)
Postcodebox.Value = Postcode

Set Postcodebox2 = inputform.Item(1)
Postcodebox2.Value = Postcode2

Set POSTCODEbutton = inputform.Item(2)
POSTCODEbutton.Click

Do While IE.readyState < 4 Or IE.busy = True
DoEvents
Loop


Set Table = IE.document.getElementsByTagname("Table")
Set DistanceTable = Table.Item(3)

Set DistanceRow = DistanceTable.Rows(2)
distance = Val(Trim(DistanceRow.Cells(2).innertext))
With Worksheets("sheet1")
.Range("A1").Value = distance
End With

IE.Quit
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default Request for Postal Codes


Hi Joel,

This is the real answer to my question posted some days ago. Maybe you
remember, you sent a sub to me, but that didn't cover exactly my question.

Thanks,
Stefi


€˛Joel€¯ ezt Ć*rta:

This request disappeared from the postings. do'nt know why. Here is the
solution

Sub Private Commandbutton1_Click()

Postcode = InputBox("Enter PostCode: ")

Postcode2 = InputBox("Enter 2nd PostCode: ")


Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True

URL = _
"http://www.postcode.org.uk/country/uk/_postcode-distance-calculator.asp"
IE.Navigate2 URL

Do While IE.readyState < 4 Or IE.busy = True
DoEvents
Loop

Set MyForm = IE.document.getElementsByTagname("Form")
Set inputform = MyForm.Item(0)

Set Postcodebox = inputform.Item(0)
Postcodebox.Value = Postcode

Set Postcodebox2 = inputform.Item(1)
Postcodebox2.Value = Postcode2

Set POSTCODEbutton = inputform.Item(2)
POSTCODEbutton.Click

Do While IE.readyState < 4 Or IE.busy = True
DoEvents
Loop


Set Table = IE.document.getElementsByTagname("Table")
Set DistanceTable = Table.Item(3)

Set DistanceRow = DistanceTable.Rows(2)
distance = Val(Trim(DistanceRow.Cells(2).innertext))
With Worksheets("sheet1")
.Range("A1").Value = distance
End With

IE.Quit
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Request for Postal Codes


If you told me is was for postal codes I would of givin you my US zipcode
macro which has a userform like the postal code. Enter 10001 to get NYC main
post office.

Sub GetZipCodes()

ZIPCODE = InputBox("Enter 5 digit zipcode : ")

Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True

URL = "http://zip4.usps.com/zip4/citytown_zip.jsp"

'get web page
IE.Navigate2 URL
Do While IE.readyState < 4
DoEvents
Loop

Do While IE.busy = True
DoEvents
Loop
Set Form = IE.document.getElementsByTagname("Form")

Set zip5 = IE.document.getElementById("zip5")
zip5.Value = ZIPCODE

Form(0).submit
Do While IE.busy = True
DoEvents
Loop

Set Table = IE.document.getElementsByTagname("Table")
If Table(0).Rows(0).innertext = "" Then
MsgBox ("Invalid Zip code")
Else
Location = Table(0).Rows(2).innertext
End If
IE.Quit
MsgBox ("Zip code = " & ZIPCODE & " City/State = " & Location)


End Sub



"Stefi" wrote:

Hi Joel,

This is the real answer to my question posted some days ago. Maybe you
remember, you sent a sub to me, but that didn't cover exactly my question.

Thanks,
Stefi


€˛Joel€¯ ezt Ć*rta:

This request disappeared from the postings. do'nt know why. Here is the
solution

Sub Private Commandbutton1_Click()

Postcode = InputBox("Enter PostCode: ")

Postcode2 = InputBox("Enter 2nd PostCode: ")


Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True

URL = _
"http://www.postcode.org.uk/country/uk/_postcode-distance-calculator.asp"
IE.Navigate2 URL

Do While IE.readyState < 4 Or IE.busy = True
DoEvents
Loop

Set MyForm = IE.document.getElementsByTagname("Form")
Set inputform = MyForm.Item(0)

Set Postcodebox = inputform.Item(0)
Postcodebox.Value = Postcode

Set Postcodebox2 = inputform.Item(1)
Postcodebox2.Value = Postcode2

Set POSTCODEbutton = inputform.Item(2)
POSTCODEbutton.Click

Do While IE.readyState < 4 Or IE.busy = True
DoEvents
Loop


Set Table = IE.document.getElementsByTagname("Table")
Set DistanceTable = Table.Item(3)

Set DistanceRow = DistanceTable.Rows(2)
distance = Val(Trim(DistanceRow.Cells(2).innertext))
With Worksheets("sheet1")
.Range("A1").Value = distance
End With

IE.Quit
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default Request for Postal Codes


Thanks, Joel, I was not after postal codes in particular but the searching
technique in general. I learned a lot from both of your macros.
Regards,
Stefi

€˛Joel€¯ ezt Ć*rta:

If you told me is was for postal codes I would of givin you my US zipcode
macro which has a userform like the postal code. Enter 10001 to get NYC main
post office.

Sub GetZipCodes()

ZIPCODE = InputBox("Enter 5 digit zipcode : ")

Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True

URL = "http://zip4.usps.com/zip4/citytown_zip.jsp"

'get web page
IE.Navigate2 URL
Do While IE.readyState < 4
DoEvents
Loop

Do While IE.busy = True
DoEvents
Loop
Set Form = IE.document.getElementsByTagname("Form")

Set zip5 = IE.document.getElementById("zip5")
zip5.Value = ZIPCODE

Form(0).submit
Do While IE.busy = True
DoEvents
Loop

Set Table = IE.document.getElementsByTagname("Table")
If Table(0).Rows(0).innertext = "" Then
MsgBox ("Invalid Zip code")
Else
Location = Table(0).Rows(2).innertext
End If
IE.Quit
MsgBox ("Zip code = " & ZIPCODE & " City/State = " & Location)


End Sub



"Stefi" wrote:

Hi Joel,

This is the real answer to my question posted some days ago. Maybe you
remember, you sent a sub to me, but that didn't cover exactly my question.

Thanks,
Stefi


€˛Joel€¯ ezt Ć*rta:

This request disappeared from the postings. do'nt know why. Here is the
solution

Sub Private Commandbutton1_Click()

Postcode = InputBox("Enter PostCode: ")

Postcode2 = InputBox("Enter 2nd PostCode: ")


Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True

URL = _
"http://www.postcode.org.uk/country/uk/_postcode-distance-calculator.asp"
IE.Navigate2 URL

Do While IE.readyState < 4 Or IE.busy = True
DoEvents
Loop

Set MyForm = IE.document.getElementsByTagname("Form")
Set inputform = MyForm.Item(0)

Set Postcodebox = inputform.Item(0)
Postcodebox.Value = Postcode

Set Postcodebox2 = inputform.Item(1)
Postcodebox2.Value = Postcode2

Set POSTCODEbutton = inputform.Item(2)
POSTCODEbutton.Click

Do While IE.readyState < 4 Or IE.busy = True
DoEvents
Loop


Set Table = IE.document.getElementsByTagname("Table")
Set DistanceTable = Table.Item(3)

Set DistanceRow = DistanceTable.Rows(2)
distance = Val(Trim(DistanceRow.Cells(2).innertext))
With Worksheets("sheet1")
.Range("A1").Value = distance
End With

IE.Quit
End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 279
Default Request for Postal Codes

In message of Fri,
26 Jun 2009 05:20:01 in microsoft.public.excel.programming, Stefi
writes

Thanks, Joel, I was not after postal codes in particular but the searching
technique in general. I learned a lot from both of your macros.
Regards,
Stefi


[snip]
Me too! I used some of Joel's code in another thread to write something
to open a URL and extract some data. I hope to use the code in an
earlier posting in this thread to drive the HTML as if by a human.

What techniques do you (Joel) use to analyse an HTML page?

This thread is disconnected from its origin. I have failed to find that
in Google groups. It would help to put Joel's posting in context.
--
Walter Briscoe


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 267
Default Request for Postal Codes

Hi Joel
Was wondering, how do you know how to refer to any particular item on a web
site in VBA?
In the example you gave in response to my question how do you know that the
output data is embeded in an object with tag name "table" or that the input
data is under tag name "form" etc!
I ask because I am looking at how I may do similar things with other web
sites eg how I might use a site like multi map to achieve the same results!
In Multi map the data goes into two input boxes but these do not appear to
be referred to as "form" in this example.
thanks John

"Joel" wrote:

If you told me is was for postal codes I would of givin you my US zipcode
macro which has a userform like the postal code. Enter 10001 to get NYC main
post office.

Sub GetZipCodes()

ZIPCODE = InputBox("Enter 5 digit zipcode : ")

Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True

URL = "http://zip4.usps.com/zip4/citytown_zip.jsp"

'get web page
IE.Navigate2 URL
Do While IE.readyState < 4
DoEvents
Loop

Do While IE.busy = True
DoEvents
Loop
Set Form = IE.document.getElementsByTagname("Form")

Set zip5 = IE.document.getElementById("zip5")
zip5.Value = ZIPCODE

Form(0).submit
Do While IE.busy = True
DoEvents
Loop

Set Table = IE.document.getElementsByTagname("Table")
If Table(0).Rows(0).innertext = "" Then
MsgBox ("Invalid Zip code")
Else
Location = Table(0).Rows(2).innertext
End If
IE.Quit
MsgBox ("Zip code = " & ZIPCODE & " City/State = " & Location)


End Sub



"Stefi" wrote:

Hi Joel,

This is the real answer to my question posted some days ago. Maybe you
remember, you sent a sub to me, but that didn't cover exactly my question.

Thanks,
Stefi


€˛Joel€¯ ezt Ć*rta:

This request disappeared from the postings. do'nt know why. Here is the
solution

Sub Private Commandbutton1_Click()

Postcode = InputBox("Enter PostCode: ")

Postcode2 = InputBox("Enter 2nd PostCode: ")


Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True

URL = _
"http://www.postcode.org.uk/country/uk/_postcode-distance-calculator.asp"
IE.Navigate2 URL

Do While IE.readyState < 4 Or IE.busy = True
DoEvents
Loop

Set MyForm = IE.document.getElementsByTagname("Form")
Set inputform = MyForm.Item(0)

Set Postcodebox = inputform.Item(0)
Postcodebox.Value = Postcode

Set Postcodebox2 = inputform.Item(1)
Postcodebox2.Value = Postcode2

Set POSTCODEbutton = inputform.Item(2)
POSTCODEbutton.Click

Do While IE.readyState < 4 Or IE.busy = True
DoEvents
Loop


Set Table = IE.document.getElementsByTagname("Table")
Set DistanceTable = Table.Item(3)

Set DistanceRow = DistanceTable.Rows(2)
distance = Val(Trim(DistanceRow.Cells(2).innertext))
With Worksheets("sheet1")
.Range("A1").Value = distance
End With

IE.Quit
End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Postal codes Karin Excel Discussion (Misc queries) 4 April 19th 08 05:43 PM
international postal codes JJ Johnson Excel Worksheet Functions 3 November 10th 07 03:23 PM
formula for Canadian Postal Codes LB Excel Worksheet Functions 6 January 25th 07 06:30 PM
UK Postal codes in Excel Paul G Excel Worksheet Functions 6 October 30th 06 12:07 PM
Distances between Postal Codes Irfan Excel Discussion (Misc queries) 1 May 31st 06 10:49 PM


All times are GMT +1. The time now is 05:01 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"