A
Atishoo
Hi
I am adapting the following sub to work with a more accurate web site (one
that calculates distances based on the full post code)
I am getting object variable / block variable not set on the last line:
c.Offset(1, 1) = Val(Trim(DistanceRow.Cells(2).innertext)).
Am i referencing the IE table incorectly?
Any ideas apreciated.
Private Sub CommandButton1_Click()
For Each c In Worksheets("Sheet1").Range("D6:N6").Cells
If c.Offset(0, 1).Value <> "" Then
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
URL = "http://www.driving-distances.com/distances-between-calculator.php"
IE.Navigate2 URL
Do While IE.readyState <> 4
DoEvents
Loop
Do While IE.busy = True
DoEvents
Loop
Set Form = IE.document.getElementsByTagname("Form")
Set inputform = Form.Item(0)
Set Postcodebox = inputform.Item(0)
Postcodebox.Value = c.Value
Set Postcodebox2 = inputform.Item(1)
Postcodebox2.Value = c.Offset(0, 1).Value
Set POSTCODEbutton = inputform.Item(2)
POSTCODEbutton.Click
Do While IE.busy = True
Loop
Set Table = IE.document.getElementsByTagname("table")
Set DistanceTable = Table.Item(1)
Set DistanceRow = DistanceTable.Rows(6)
c.Offset(1, 1) = Val(Trim(DistanceRow.Cells(2).innertext))
IE.Quit
End If
Next
End Sub
I am adapting the following sub to work with a more accurate web site (one
that calculates distances based on the full post code)
I am getting object variable / block variable not set on the last line:
c.Offset(1, 1) = Val(Trim(DistanceRow.Cells(2).innertext)).
Am i referencing the IE table incorectly?
Any ideas apreciated.
Private Sub CommandButton1_Click()
For Each c In Worksheets("Sheet1").Range("D6:N6").Cells
If c.Offset(0, 1).Value <> "" Then
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
URL = "http://www.driving-distances.com/distances-between-calculator.php"
IE.Navigate2 URL
Do While IE.readyState <> 4
DoEvents
Loop
Do While IE.busy = True
DoEvents
Loop
Set Form = IE.document.getElementsByTagname("Form")
Set inputform = Form.Item(0)
Set Postcodebox = inputform.Item(0)
Postcodebox.Value = c.Value
Set Postcodebox2 = inputform.Item(1)
Postcodebox2.Value = c.Offset(0, 1).Value
Set POSTCODEbutton = inputform.Item(2)
POSTCODEbutton.Click
Do While IE.busy = True
Loop
Set Table = IE.document.getElementsByTagname("table")
Set DistanceTable = Table.Item(1)
Set DistanceRow = DistanceTable.Rows(6)
c.Offset(1, 1) = Val(Trim(DistanceRow.Cells(2).innertext))
IE.Quit
End If
Next
End Sub