Excel cannot shorten a URL with a formula. WEBSERVICE sends a GET request with no headers and no body, and a modern shortener API needs a POST with an Authorization header and JSON. It is also Windows-only. Every formula-based tutorial you find is built on a service that accepted the long URL as a query parameter, and those services are gone.
So the real question is which of the three working routes fits your sheet: an Office Script, a Power Automate flow, or a bulk import with a copy-paste. The answer depends almost entirely on how often the sheet has to run.
Route One: An Office Script
Office Scripts run TypeScript against the workbook and can call an external API with fetch. This is the route for a sheet you open and run by hand.
async function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
const rows = sheet.getUsedRange().getValues();
for (let i = 1; i < rows.length; i++) {
const destination = String(rows[i][0]);
if (!destination || rows[i][1]) continue; // skip blanks and already-done rows
const response = await fetch("https://api.elido.app/v1/links", {
method: "POST",
headers: {
Authorization:
"Bearer " + workbook.getWorksheet("Config").getRange("B1").getText(),
"Content-Type": "application/json",
"Idempotency-Key": destination, // stable per row, so a re-run creates nothing
},
body: JSON.stringify({ destination_url: destination }),
});
const link = (await response.json()) as { short_url: string };
sheet.getCell(i, 1).setValue(link.short_url);
}
}
Three constraints that bite in order.
The big one: external fetch calls work when the script runs in Excel and not when Power Automate runs it. A script that works perfectly from the Automate tab fails with fetch is not defined the moment a flow triggers it, and that surprise has cost a lot of people an afternoon.
There is no secret storage and no OAuth flow, so the key sits in the script or in a cell. Reading it from a Config sheet, as above, is marginally better because the script can be shared without the key, but the workbook itself is now a credential.
And the target API must allow the call from the script's origin. Office Scripts documents a CORS requirement on external resources, which most public APIs satisfy and some internal ones do not.
The if (rows[i][1]) continue line is what makes the script safe to run twice: rows that already have a short link are skipped, and the idempotency key covers the rest.
Route Two: A Power Automate Flow
For anything on a schedule, a flow is the honest answer, because it runs whether or not anyone has the workbook open.
The shape: a recurrence or file trigger, List rows present in a table from the Excel connector, an apply-to-each with the HTTP action posting to the links endpoint, then Update a row writing the short link back.
Two things to know before building it. The generic HTTP action is a premium connector, so this route depends on your licence rather than your skill. And the flow can store the API key in a secure input or pull it from Azure Key Vault, which is a genuine improvement on the Office Script route: the credential stops living in a file people email each other.
If the flow will process hundreds of rows, add a concurrency limit on the apply-to-each. The default fan-out is generous enough to trip an API rate limit, and the fix is one setting rather than a redesign.
Route Three: Export, Bulk Import, Paste Back
For a one-off, this beats both of the above on time-to-finished. Export the destination column to CSV, run it through the shortener's bulk import, download the result, paste the short links back beside the originals.
No premium connector, no key in a workbook, no script to maintain. The Google Sheets bulk import guide covers the file format, which is the same regardless of which spreadsheet produced it, and bulk QR code generation covers the version where each row also needs a printable code.
The decision rule is simple. Once is a paste. Every Monday is a flow. Whenever someone opens the workbook is an Office Script.
Want to try the paste route first? Create an account on the free plan, import a five-row CSV, and see whether the automation is worth building at all.
Why a Formula Would Still Be Wrong
Suppose WEBSERVICE could POST. It would still be the wrong tool, because formulas recalculate on Excel's schedule rather than yours. Open the workbook, and every row fires its request again. Without an idempotency key that mints a duplicate link per row per open; with one it is merely a burst of pointless traffic that eats your rate limit.
Anything that creates a resource belongs in code that runs when you say so, not in a cell that recalculates when the application feels like it. That is worth internalising beyond this one case: it is the same reason people get burned putting RAND() or NOW() in a sheet that feeds a report.
Getting the Result Back Into the Sheet
Whichever route you pick, write four columns, not two: the original URL, the short link, the slug, and a status or error message. A run that half-finished is then obvious and re-runnable, rather than a column with silent gaps.
Keep the file. When someone asks in three months which link went in which mailing, the sheet is the answer, and rebuilding it from the dashboard is more work than keeping it was. If the same links need click data alongside them, how to track link clicks covers the export side.
Read the Cornerstone Series
This sits in the engineering cluster. Start with the free URL shortener API guide for the request shape, then rate limits and idempotency for behaving well in a loop. For the PowerShell version of the same CSV job, see how to shorten a URL in PowerShell.
Related on the Blog
Perguntas frequentes
Can I shorten a URL with an Excel formula?
Not with a modern shortener API. WEBSERVICE sends a GET request with no headers, so it cannot authenticate or send a JSON body, and it is Windows-only. Any tutorial showing a formula-based shortener is using an old service that accepted the long URL as a query parameter.
How do I shorten URLs in Excel then?
Three routes work: an Office Script with fetch for a one-off run inside the app, a Power Automate flow with the HTTP action for anything scheduled, or exporting the column to CSV and using a bulk import. Pick by how often the sheet has to run rather than by what looks cleverest.
Why does fetch fail in my Office Script when Power Automate runs it?
Because external fetch calls are not available in the Power Automate runtime, only when the script runs in Excel itself. The script that works from the Automate tab in the app fails with fetch is not defined when a flow triggers it, which is the single most common surprise here.
Does Office Scripts support OAuth or secret storage?
No. There is no sign-in flow and no secret store, so a key has to be hardcoded in the script or read from a cell. Treat any workbook containing that script as a credential: do not share it broadly, and use a key scoped to link creation.
How do I avoid creating duplicate links every time the sheet recalculates?
Send an idempotency key derived from the destination URL, so a repeat request returns the existing link rather than a new one. This is also why a formula would be the wrong tool even if it could POST: formulas recalculate on their own schedule and would mint links every time.
What is the fastest way to shorten a few hundred rows once?
Export the column to CSV and use the shortener's bulk import, then paste the returned short links back beside the originals. No code, no premium connector, and it takes a couple of minutes. Automate only when the same job repeats on a schedule.
Experimente Elido
Cole uma URL, obtenha um link curto
Sem cadastro. O link vive 30 dias. Cadastre-se para mantê-lo para sempre.
Grátis, sem necessidade de registo · 2 por dia