Hi
I've some, but limited experience, with VBA and macros generally.
I am trying to extract data from pages such as this:
http://idoxpa.westminster.gov.uk/online-applications/applicationDetails.do?activeTab=summary&keyVal=MFZP5PRP01R00
Specifically the value next to the "Status" row.
The page is generated by inserting a reference into the box on:
http://idoxpa.westminster.gov.uk/online-applications/
In this case reference 13/00001
(The 'KEYVAL' in the url of the results page seems to be generated at random so I can't be used to access the file directly).
I have set up a macro that queries the first web page with a reference from Cell A1 (where the references follow the pattern 13/00001, 13/00002, etc), but I can't work out how to then extract the information from the relevant cell in the HTML table on the results page.
"Sub IE_Autiomation()
Dim i As Long
Dim IE As Object
Dim objElement As Object
Dim objCollection As Object
Dim ieTable As Object
Dim clip As Object
' Create InternetExplorer Object
Set IE = CreateObject("InternetExplorer.Application")
' You can uncoment Next line To see form results
IE.Visible = True
' Send the form data To URL As POST binary request
IE.Navigate "http://idoxpa.westminster.gov.uk/online-applications/"
' Wait while IE loading...
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
Set objCollection = IE.document.getElementsByTagName("input")
i = 0
While i < objCollection.Length
If objCollection(i).Name = "searchCriteria.simpleSearchString" Then
' Set text for search
objCollection(i).Value = Range("A1").Value
Else
If objCollection(i).Type = "submit" And _
objCollection(i).Name = "" Then
' "Search" button is found
Set objElement = objCollection(i)
End If
End If
i = i + 1
Wend
objElement.Click ' click button to search
' Wait while IE re-loading...
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
'Set ieTable = IE.all.Item("simpleDetailsTable")
result = IE.document.body.innerHTML
'copy the tables html to the clipboard and paste to teh sheet
'If Not ieTable Is Nothing Then
' clip.SetText "<html>" & ieTable.outerHTML & "</html>"
' clip.PutInClipboard
' Sheet1.Select
' Sheet1.Range("A1").Select
' Sheet1.PasteSpecial "Unicode Text"
'End If
'Sheet1.Range("A2") = IE.all.Item("simpleDetailsTable")
' Show IE
IE.Visible = True
' Clean up
Set IE = Nothing
Set objElement = Nothing
Set objCollection = Nothing
Application.StatusBar = ""
End Sub
You can see from the commented lines at the end that I have stumbled around a bit unsuccesfully.
I think, although I could be wrong, that I can't use the webquery function because I don't know the url I need from the outset, and as I only need one or two cells from the webpage I thought trying to extract them directly might be easier.
Any help would be very gratefully received, or pointers to similar posts.
Many thanks.
I've some, but limited experience, with VBA and macros generally.
I am trying to extract data from pages such as this:
http://idoxpa.westminster.gov.uk/online-applications/applicationDetails.do?activeTab=summary&keyVal=MFZP5PRP01R00
Specifically the value next to the "Status" row.
The page is generated by inserting a reference into the box on:
http://idoxpa.westminster.gov.uk/online-applications/
In this case reference 13/00001
(The 'KEYVAL' in the url of the results page seems to be generated at random so I can't be used to access the file directly).
I have set up a macro that queries the first web page with a reference from Cell A1 (where the references follow the pattern 13/00001, 13/00002, etc), but I can't work out how to then extract the information from the relevant cell in the HTML table on the results page.
"Sub IE_Autiomation()
Dim i As Long
Dim IE As Object
Dim objElement As Object
Dim objCollection As Object
Dim ieTable As Object
Dim clip As Object
' Create InternetExplorer Object
Set IE = CreateObject("InternetExplorer.Application")
' You can uncoment Next line To see form results
IE.Visible = True
' Send the form data To URL As POST binary request
IE.Navigate "http://idoxpa.westminster.gov.uk/online-applications/"
' Wait while IE loading...
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
Set objCollection = IE.document.getElementsByTagName("input")
i = 0
While i < objCollection.Length
If objCollection(i).Name = "searchCriteria.simpleSearchString" Then
' Set text for search
objCollection(i).Value = Range("A1").Value
Else
If objCollection(i).Type = "submit" And _
objCollection(i).Name = "" Then
' "Search" button is found
Set objElement = objCollection(i)
End If
End If
i = i + 1
Wend
objElement.Click ' click button to search
' Wait while IE re-loading...
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
'Set ieTable = IE.all.Item("simpleDetailsTable")
result = IE.document.body.innerHTML
'copy the tables html to the clipboard and paste to teh sheet
'If Not ieTable Is Nothing Then
' clip.SetText "<html>" & ieTable.outerHTML & "</html>"
' clip.PutInClipboard
' Sheet1.Select
' Sheet1.Range("A1").Select
' Sheet1.PasteSpecial "Unicode Text"
'End If
'Sheet1.Range("A2") = IE.all.Item("simpleDetailsTable")
' Show IE
IE.Visible = True
' Clean up
Set IE = Nothing
Set objElement = Nothing
Set objCollection = Nothing
Application.StatusBar = ""
End Sub
You can see from the commented lines at the end that I have stumbled around a bit unsuccesfully.
I think, although I could be wrong, that I can't use the webquery function because I don't know the url I need from the outset, and as I only need one or two cells from the webpage I thought trying to extract them directly might be easier.
Any help would be very gratefully received, or pointers to similar posts.
Many thanks.