Macro to query website search funtion

mikeymay

Well-known Member
Joined
Jan 17, 2006
Messages
1,645
Office Version
  1. 365
Platform
  1. Windows
I have a list of 800ish unique establishment references and I need to enter each one into a search box on a website to get a specific item of information form the result.

I can see there are quite a few solutions out there but I need to get this done ASAP and as I need to work on other areas of the project I'm going to struggle to develop an existing piece of code so I was hoping someone could point me in the general right direction.

The website isAdvanced searchand I need to enter a URN reference after selecting 'To find out a specific establishment fill in its identifier' - 140764 is an example

From the result I need to get the Postcode (this needs to be selected form the option to 'show additional columns') and the URN and postcode to be added to a blank Excel file.


TIA
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Try the following:

Code:
Sub ListPostalCode()
'get Postal Code  from URN
   Application.Calculation = xlCalculationManual
   Application.ScreenUpdating = False
   On Error Resume Next
   Dim Cell As Range, rng As Range
   Dim URN As String
    Set rng = Selection
     For Each Cell In rng
     If Cell <> vbNullString And Cell.EntireRow.Hidden = False Then
          URN = Cell.Value
     Cell.Offset(0, 1) = getURN(URN)
     End If
     Next Cell
   Application.Calculation = xlCalculationAutomatic
   Application.ScreenUpdating = True
End Sub


Public Function getURN(Number As String)
    On Error GoTo errorhandler:
    
    'Function to get URN Postal Code from URN number
    Web_URL = "http://www.education.gov.uk/edubase/establishment/summary.xhtml?urn=" & Number
 
 
    With CreateObject("msxml2.xmlhttp")
        .Open "GET", Web_URL, False
        .send
        resultstring = .responseText
    End With
    
    emptyresult = "*Establishment is not found*"
    
    If resultstring = emptyresult Then
        getURN = "URN not found"
        Exit Function
    End If
    
    searchstring = "postal-code"
    namestart = InStr(1, resultstring, searchstring) + 13
   Nameend = InStr(namestart, resultstring, "<") - namestart
    finalname = Mid(resultstring, namestart, Nameend)
    getURN = finalname
    Exit Function
errorhandler:
    getURN = "Error in Request"
End Function

Be sure to select the URNs you want the Postal Codes for in Excel
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,190
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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