In case it's useful to anyone, I've put together a somewhat light (and not fully featured) wrapper around the companies house web based API - https://developer.companieshouse.gov...ocs/index.html
It handles the web call, the parsing of the JSON response and maps it to strongly typed objects, allowing you to write code such as this:
There's a workbook attached including the above code in a UserForm, and the necessary classes to encapsulate everything.![]()
Option Explicit Dim api As CompaniesHouseAPI Private Sub UserForm_Initialize() Set api = New CompaniesHouseAPI api.companiesHouseBaseUrl = Constants.BASE_URL_API api.companiesHouseApiKey = Constants.API_KEY Me.getOfficers.Enabled = False End Sub Private Sub searchButton_Click() Dim companySearchResults As CHSearchResultCompany Dim company As CHSearchResultItemCompany Dim x As Long Me.ListBox1.Clear Set companySearchResults = api.companySearch(Me.searchBox.text, 50, 0) MsgBox "Total results found:" & companySearchResults.total_results Me.ListBox1.ColumnCount = 4 Me.ListBox1.ColumnWidths = "0;250;250" For Each company In companySearchResults Me.ListBox1.AddItem Me.ListBox1.List(x, 0) = company.company_number Me.ListBox1.List(x, 1) = company.title Me.ListBox1.List(x, 2) = company.description x = x + 1 Next End Sub Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean) Dim company As CHCompany If Me.ListBox1.ListCount > 0 Then Set company = api.companyById(Me.ListBox1.Value) Me.CompanyName = company.company_name Me.CompanyNumber = company.company_number Me.CompanyStatus = company.company_status & " - " & company.company_status_detail With company.registered_office_address Me.CompanyAddress = .address_line_1 & vbCr & _ .address_line_2 & vbCr & _ .region & vbCr & _ .country & vbCr & _ .postal_code End With Me.getOfficers.Enabled = True End If End Sub Private Sub getOfficers_Click() Dim officers As CHOfficerList Dim officer As CHOfficerListItem Dim temp As String If Len(Me.CompanyNumber.Caption) > 0 Then Set officers = api.companyById(Me.CompanyNumber.Caption).officers MsgBox "Officers listed: " & officers.active_count For Each officer In officers temp = temp & officer.name & vbCr temp = temp & officer.nationality & vbCr temp = temp & officer.occupation & vbCr temp = temp & officer.country_of_residence & vbCr temp = temp & vbCr temp = temp & "----------------------------------" temp = temp & vbCr Next officer MsgBox temp End If End Sub
To use it, you'll need to sign up for a free developer API key and put that in.
Currently supports:
- Company Search
- Officer Search
- Company Details, including officers
If anyone fancies adding the rest of the data structures (it's very easy, it's just data mapping), I've got a Node (JavaScript) script that generates the classes (ish) from a JavaScript object - most of it is just boiler plate code - let me know and I'll send it over.
Enjoy
P.S This won't work on a Mac and I have no inclination to make it do so.
Bookmarks