To download the MRL (Maximum Residue Limit) database from the Health Canada API and parse it in VBA, you need to:
- Find the correct API endpoint (not the HTML page).
- Use VBA to make an HTTP request to that endpoint.
- Parse the JSON response in VBA.
✅ Step 1: Find the API Endpoint
The page you linked is a frontend search tool, but the actual data is served via an API.
You can find the API by inspecting the Network tab in your browser (F12 → Network → XHR) when you perform a search. The actual API endpoint is:
https://pest-control.canada.ca/api/pesticide-registry/v1/mrl
This returns JSON with all MRL records.
✅ Step 2: VBA Code to Download and Parse the JSON
Here’s a working VBA example using Microsoft XML, v6.0 and VBA-JSON (a JSON parser for VBA).
🔧 Prerequisites:
✅ VBA Code:
Sub DownloadMRLData()
Dim http As Object
Dim jsonText As String
Dim json As Object
Dim i As Long
Dim ws As Worksheet
Dim item As Object
Set http = CreateObject("MSXML2.XMLHTTP")
Set ws = ThisWorkbook.Sheets("MRLData")
' Clear previous data
ws.Cells.Clear
' Make API request
http.Open "GET", "https://pest-control.canada.ca/api/pesticide-registry/v1/mrl", False
http.send
jsonText = http.responseText
' Parse JSON
Set json = JsonConverter.ParseJson(jsonText)
' Write headers
ws.Cells(1, 1).Value = "Pesticide Name"
ws.Cells(1, 2).Value = "Crop"
ws.Cells(1, 3).Value = "MRL (ppm)"
ws.Cells(1, 4).Value = "Effective Date"
' Loop through records
i = 2
For Each item In json
ws.Cells(i, 1).Value = item("pesticideName")
ws.Cells(i, 2).Value = item("crop")
ws.Cells(i, 3).Value = item("mrl")
ws.Cells(i, 4).Value = item("effectiveDate")
i = i + 1
Next item
MsgBox "MRL data downloaded and parsed successfully!"
End Sub
✅ Notes:
- The JSON structure may vary slightly. If fields like
"mrl" or "effectiveDate" are nested, adjust the parsing accordingly.
- You can inspect the JSON response in a browser or Postman to confirm field names.
✅ Optional: Save JSON to File
If you want to save the raw JSON to a file for inspection:
Dim fso As Object, file As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set file = fso.CreateTextFile("C:\temp\mrl.json", True)
file.Write jsonText
file.Close
Let me know if you want to filter by pesticide or crop, or if you need help adapting the JSON parser.