How to Integrate Claude to Excel via API
How to Integrate Claude to Excel
If you want Claude to read data from a spreadsheet, generate text, classify rows, or write formulas on demand, you need to connect Excel to Claude's API. Excel has no native Claude plugin, so the integration happens through one of three channels: Office Scripts (for Excel on the web and Microsoft 365), VBA with WinHttpRequest (for desktop Excel), or Power Query with Web.Contents (for refreshable data pulls). All three ultimately do the same thing: send an HTTP POST request with your prompt and get back a JSON response you parse into cells.
The rest of this guide walks through each method with working code, plus how to avoid the two most common blockers: getting a usable API key and handling authentication headers inside Excel's limited HTTP tooling.
What you actually need before starting
Regardless of which method you pick, you need:
- An API key. Anthropic's console issues keys, but if you already pay for a Claude subscription (Pro, Max, Team), SubToAPI turns that access into a standard
sub_live_...API key you can call over plain HTTPS — useful if you don't want a separate Anthropic API billing account just for a spreadsheet macro. - A stable endpoint. You'll be hitting a
/v1/messages-style endpoint with a JSON body containingmodel,messages, andmax_tokens. - A way to store the key securely. Never hardcode it in a shared workbook — use Windows Credential Manager, an environment variable, or a config sheet that isn't shared outside your org.
Method 1: VBA with WinHttpRequest
This is the most common approach for desktop Excel because it doesn't require Microsoft 365 or any add-in installation. It works in Excel 2016 and later.
Sub CallClaude()
Dim http As Object
Dim url As String
Dim body As String
Dim apiKey As String
apiKey = Environ("SUBTOAPI_KEY")
url = "https://api.subtoapi.app/v1/messages"
body = "{""model"":""claude-sonnet-4"",""max_tokens"":300," & _
"""messages"":[{""role"":""user"",""content"":""" & _
Range("A1").Value & """}]}"
Set http = CreateObject("WinHttp.WinHttpRequest.5.1")
http.Open "POST", url, False
http.SetRequestHeader "Content-Type", "application/json"
http.SetRequestHeader "Authorization", "Bearer " & apiKey
http.Send body
Range("B1").Value = http.ResponseText
End Sub
This sends whatever text is in cell A1 as a prompt and writes the raw JSON response into B1. In practice you'll want to parse the response instead of dumping raw JSON — VBA doesn't have a built-in JSON parser, so most people either write a small string-extraction routine or import a JSON library like VBA-JSON.
A cleaner version extracts just the text field:
Function GetClaudeText(responseText As String) As String
Dim startPos As Long, endPos As Long
startPos = InStr(responseText, """text"":""") + 8
endPos = InStr(startPos, responseText, """")
GetClaudeText = Mid(responseText, startPos, endPos - startPos)
End Function
Call it after the HTTP request with Range("B1").Value = GetClaudeText(http.ResponseText).
Method 2: Office Scripts (Excel on the web / Microsoft 365)
If your workbook lives in OneDrive or SharePoint, Office Scripts (TypeScript-based) is a better fit than VBA and works across desktop and web Excel.
async function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
const prompt = sheet.getRange("A1").getValue().toString();
const response = await fetch("https://api.subtoapi.app/v1/messages", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${process.env.SUBTOAPI_KEY}`
},
body: JSON.stringify({
model: "claude-sonnet-4",
max_tokens: 300,
messages: [{ role: "user", content: prompt }]
})
});
const data = await response.json();
sheet.getRange("B1").setValue(data.content[0].text);
}
Office Scripts doesn't support process.env, so in practice you'll paste the key directly into the script (fine for personal use) or fetch it from a secured Azure Key Vault call if you're running this in a business environment. This script can also be triggered by a Power Automate flow, which lets you run it on a schedule or when a row is added — useful for batch-processing spreadsheet rows through Claude without opening Excel manually.
Method 3: Power Query (Web.Contents)
Power Query is the right tool when you want Claude's output to refresh automatically as part of a data model, rather than firing one-off requests from a button.
let
apiKey = "Bearer YOUR_KEY_HERE",
body = "{""model"":""claude-sonnet-4"",""max_tokens"":200,""messages"":[{""role"":""user"",""content"":""Summarize this: " & Text.From([Column1]) & """}]}",
response = Web.Contents(
"https://api.subtoapi.app/v1/messages",
[
Headers = [#"Content-Type"="application/json", Authorization=apiKey],
Content = Text.ToBinary(body)
]
),
json = Json.Document(response),
text = json[content]{0}[text]
in
text
Wrap this in a custom function and apply it as a new column against a table, and every row gets its own Claude call on refresh. Be careful with rate limits here — refreshing a 500-row table means 500 API calls in quick succession, which is where usage metadata and per-key rate limiting matter (see the streaming and tools docs if you're batching structured extraction rather than free text).
Where SubToAPI fits
All three methods above assume you have an HTTPS endpoint and a bearer token — SubToAPI provides both without requiring a separate Anthropic developer account, which is handy if your team already has Claude subscriptions and just wants to expose that access to Excel, Power Automate, or a shared macro. Setup is a signup, an API key, and a call to /v1/messages, documented in the quickstart and messages guides. Team and Scale plans add per-seat keys, so different spreadsheets or departments can use separate keys without sharing credentials — check pricing for the current tiers, or start with the free trial.
Questions
Can Excel call Claude without any add-in or VBA? No native connector exists yet. You always need either a script (VBA, Office Script) or Power Query's Web.Contents to make the HTTP call — there's no built-in "Claude" ribbon button.
Will this work in Excel for Mac? VBA with WinHttpRequest is Windows-only. On Mac, use Office Scripts (if you're on Microsoft 365) or Power Query, both of which are cross-platform.
How do I avoid hitting rate limits when processing many rows? Batch requests where possible, add a short delay between calls in your script, and use a key with clear per-key usage tracking so you can see consumption before you hit a ceiling — this is easier to monitor with a dedicated API key than a shared subscription login.