You can import JSON into Excel with VBA by having a script fetch or read the JSON text, parse it into objects and arrays, then loop over those items and write each field into cells. Excel itself has no built-in JSON parser in VBA, so the usual approach is either to use a small JSON parsing class module, or to lean on a helper such as the ScriptControl on older 32-bit Office installs (which is unreliable on 64-bit Office and modern builds) or PowerShell/Node via a shell call. The class-module route is the most portable and the one worth learning.

What You'll Need

  • Excel with macros enabled (a .xlsm workbook, since .xlsx cannot store VBA code).
  • The Developer tab visible: File > Options > Customize Ribbon and tick Developer on the right-hand list. Exact wording can differ slightly by version.
  • A JSON source: a local .json file, text pasted into a cell, or an HTTPS endpoint you are allowed to call.
  • A JSON parser class module. A well-known free, MIT-licensed option is VBA-JSON (sometimes called jsonConverter). You add the .bas and class .cls files via File > Import File in the VBA editor. You can also write a minimal parser yourself, but a tested one saves days of debugging.
  • Trust settings that allow macros and, if you call web endpoints, access to the required library. In the VBA editor use Tools > References to add "Microsoft WinHTTP Services, version 5.1" or "Microsoft XML, v6.0" for HTTP requests, and "Microsoft Scripting Runtime" if your parser needs Dictionary objects.

Step-by-Step

  1. Save the workbook as macro-enabled. Use File > Save As and pick Excel Macro-Enabled Workbook (*.xlsm). This must be done before you write any code, or you will lose the macro when you close the file.
  2. Open the VBA editor and import the parser. Press Alt+F11 (Windows) to open the editor. Right-click your project in the Project Explorer, choose Import File, and add the JSON parser's .bas and .cls files. On Mac, the VBA editor is reached through Tools > Macro > Visual Basic Editor; note that some Windows-only libraries (WinHTTP) are not available there, so reading a local file is the safer route on Mac.
  3. Add the references. In the editor choose Tools > References and tick the Scripting Runtime and, for HTTP, XML v6.0 (MSXML2.XMLHTTP60). Click OK. Missing references are the single most common cause of a compile error on someone else's machine.
  4. Insert a standard module. Insert > Module. This is where your import routine lives. Give it a clear name such as ImportJsonToSheet.
  5. Get the JSON text. For a file, use a simple text read: open the path with the Scripting Runtime FileSystemObject and read the whole stream. For a URL, create an MSXML2.XMLHTTP60 object, call Open "GET", url, False, then Send, and take the .responseText. Always wrap this in error handling because the request can fail before any parsing happens.
  6. Parse the text. Hand the string to the parser, for example JsonConverter.ParseJson(txt), which returns a Dictionary for an object or a Collection for an array. Assign it to a Variant variable so it can hold either type.
  7. Write a header row. Decide the columns your sheet needs (for example id, name, email, created_at) and write them into row 1. Hard-coding headers keeps the output predictable and makes the next step simple.
  8. Loop over the parsed items. If the top level is an array, loop with For Each item In parsed. If it is an object wrapping an array (a very common pattern), drill in first, for example parsed("results"), then loop. Inside the loop, read each field with item("name") and guard against missing keys: parser dictionaries throw an error on a key that does not exist, so test whether the key is present before reading it.
  9. Write each row into cells. Keep a row counter starting at 2, write the values across the columns, then increment the counter. Writing to the sheet cell by cell inside a big loop is slow; for thousands of rows, fill a Variant array first and assign it to the range in one go. Turn off ScreenUpdating while it runs and turn it back on at the end.
  10. Handle nested objects and arrays. If a field is itself an object, either flatten the keys you need into separate columns or join them into one text cell with a separator. For an array of values inside a row, join the elements into a comma-separated string. Decide this up front, because Excel cells are flat.
  11. Format and finish. Apply AutoFit to the used columns, set number formats for any date or numeric fields that arrived as text, and freeze the header row with View > Freeze Panes. Wrap the whole routine in On Error GoTo with a handler that shows Err.Description and re-enables ScreenUpdating.

Common Mistakes

  • Saving as .xlsx. The code silently disappears; always .xlsm.
  • Reading a key that is not there. Parser dictionaries error on missing keys. Check the key first, or use a helper that returns an empty string by default.
  • Assuming the top level is an array. Many APIs return an object such as { "data": [ ... ] }. Inspect the raw response before looping.
  • Confusing numbers and text. JSON numbers may land in the cell as text if the parser returns strings; convert with CLng or CDbl where you need real numbers.
  • Missing references. Code that compiles on your PC fails elsewhere because the reference was not checked. Nothing in Excel fixes this automatically.
  • Unicode load failure. Reading UTF-8 files with the wrong text mode can produce garbled characters; read as UTF-8 explicitly or accept that accented characters may need a different read approach.

Tips

  • Keep the parser class in a personal macro workbook or a template so new projects start ready.
  • Log the raw JSON to a hidden sheet the first time you run against a new endpoint; it makes field names and nesting obvious.
  • Write a tiny sample first: paste two or three records into a cell and step through with F8 (Windows) before pointing at the real source.
  • Respect the source: do not hammer an API with a loop of requests, and check whether it requires a key or has usage rules.
  • For very large payloads, consider Power Query's JSON connector first; it is built in and needs no code. Use VBA when you need the job to run automatically inside your existing macro workflow.

Troubleshooting

If the macro does not compile, open Tools > References and look for entries marked MISSING; untick and re-add the ones your code uses. If you get a runtime error on a key, print the raw text and compare field names exactly, including capitals. If every row is empty, your loop is probably iterating an object rather than the array inside it; step through and inspect the parsed variable's type. If an HTTP call fails, test the URL in a browser first; a redirect or an authentication header you did not send will fail in code while working in the browser. If the sheet fills with numbers as text, apply the conversion functions or set the column format before writing. If the workbook runs slowly, batch the writes into an array and disable ScreenUpdating.

Frequently Asked Questions

Does Excel have a built-in JSON import in VBA?

No. VBA itself cannot parse JSON. Power Query can import JSON without code, but inside a macro you need a parser class or an external helper.

Why does the parser error on a missing field?

Its dictionary raises an error for unknown keys. Check with an existence test before reading, or default to an empty value.

Can I import JSON on Excel for Mac?

Yes for local files, using the same parser and file-read approach. Windows-only libraries such as WinHTTP are not available, so fetching from a URL in VBA is not reliable there.

How do I flatten nested data?

Decide which inner fields matter, give each its own column, and join arrays into one text cell. Excel cannot hold a nested structure in a single cell.

Is there a no-code alternative?

Yes. Use Data > Get Data > From File > From JSON (labels can vary slightly by version) and expand the columns in Power Query, then load to a sheet.

Why is my export row order wrong?

The order comes from the JSON array, not from your header row. If order matters, sort the output after writing it.