This repository shows how to call the GoldAPI.io live gold price API from Microsoft Excel. It includes examples for Office Scripts, Power Query, VBA, and Excel custom functions so you can choose the integration style that fits your workbook.
Use this example if you are looking for:
- GoldAPI.io Microsoft Excel example
- GoldAPI.io Office Scripts integration
- GoldAPI.io Power Query example
- GoldAPI.io VBA macro example
- GoldAPI.io Excel custom function example
- Live gold price API in Excel
- XAU/USD API request sample for spreadsheets
- Precious metals API example for Excel workbooks
The examples call:
https://www.goldapi.io/api/XAU/USDEquivalent curl request:
curl -X GET "https://www.goldapi.io/api/XAU/USD" \
-H "x-access-token: GOLD_API_TOKEN"- Microsoft Excel
- A GoldAPI.io API token
- One of these Excel integration options:
- Office Scripts in Excel on the web
- Power Query in Excel
- VBA macros in desktop Excel
- Office Add-in custom functions
Use office-scripts/gold-api-example.ts when you want a modern script that writes live GoldAPI.io data into a worksheet.
- Open Excel on the web.
- Open the Automate tab.
- Create a new script.
- Paste the contents of
office-scripts/gold-api-example.ts. - Run the script and enter your GoldAPI.io token when prompted.
The script creates or updates a worksheet named GoldAPI with a summary table and the full JSON response.
Use power-query/GoldApiExample.pq when you want a refreshable query table in Excel.
- Create a one-cell named range or table named
GoldApiTokencontaining your GoldAPI.io token. - Open Power Query.
- Create a blank query.
- Open Advanced Editor.
- Paste the contents of
power-query/GoldApiExample.pq. - Load the query into a worksheet.
You can change Metal and Currency in the query from XAU and USD to another supported pair.
Use vba/GoldApiExample.bas when you want a desktop Excel macro.
- Open Excel desktop.
- Press
Alt+F11on Windows to open the VBA editor. - Import
vba/GoldApiExample.bas, or paste its contents into a module. - Replace
your_goldapi_token_herewith your GoldAPI.io token. - Run
FetchGoldPrice.
The VBA example uses WinHttp.WinHttpRequest.5.1, which is intended for Excel on Windows. It writes a summary table and the full JSON response to a worksheet named GoldAPI.
Use custom-functions/functions.ts when you want a worksheet function:
=GOLDPRICE("XAU","AUD")
This option is for an Excel Office Add-in custom function. The function reads the GoldAPI.io token from Office add-in storage and returns the current price value for the requested metal and currency.
The supporting metadata is in custom-functions/functions.json. See custom-functions/README.md for token setup notes.
The core GoldAPI.io request is:
const response = await fetch("https://www.goldapi.io/api/XAU/USD", {
method: "GET",
headers: {
"x-access-token": goldApiToken,
Accept: "application/json",
},
});
const data = await response.json();This repository expands that into an Excel example with:
- Worksheet creation
- Summary fields for price, bid, ask, change, exchange, and symbol
- Full JSON response output
- Configurable metal and currency pair
- Basic HTTP error handling
The custom function example returns a scalar price directly to the worksheet:
=GOLDPRICE("XAU","AUD")
{
"timestamp": 1776907250,
"metal": "XAU",
"currency": "USD",
"exchange": "FOREXCOM",
"symbol": "FOREXCOM:XAUUSD",
"prev_close_price": 4739.215,
"open_price": 4739.215,
"low_price": 4694.355,
"high_price": 4753.79,
"open_time": 1776902400,
"price": 4733.125,
"ch": -6.09,
"chp": -0.13,
"ask": 4733.72,
"bid": 4732.69,
"price_gram_24k": 152.1735,
"price_gram_22k": 139.4924,
"price_gram_21k": 133.1518,
"price_gram_20k": 126.8113,
"price_gram_18k": 114.1301,
"price_gram_16k": 101.449,
"price_gram_14k": 88.7679,
"price_gram_10k": 63.4056
}| Setting | Required | Default | Description |
|---|---|---|---|
| GoldAPI token | Yes | None | Your GoldAPI.io access token. |
| Metal | No | XAU |
Metal symbol to request. |
| Currency | No | USD |
Currency symbol to request. |
Do not commit your GoldAPI.io token to GitHub or share workbooks that contain private API tokens.
For Office Scripts, pass the token as a script parameter. For Power Query, use a workbook parameter and avoid committing workbook files. For VBA, avoid hard-coding production tokens in files that will be shared. For custom functions, store the token in add-in storage or retrieve it from your own backend instead of putting it in worksheet formulas.
MIT