Excel Error Codes

How to Fix the AccessDenied Error in an Excel Office Script addTable Call

Phi Hung VoPhi Hung Vo Nov 13, 2026 869 views

Question details

The user needs to resolve an AccessDenied error that occurs when an Office Script calls addTable on an Excel worksheet and prevent the script from failing.

How to Fix the AccessDenied Error in an Excel Office Script addTable Call
Product
Microsoft Excel for the web and Office Scripts
Device & OS
not provided
Scenario
The user is running an Office Script that gets the used range and calls addTable to create a table in an Excel worksheet.
Observed behavior
The script fails with AccessDenied at the addTable call, even in some cases when the worksheet is not protected or the workbook is new.
Before you start

Open the affected workbook in Excel for the web and confirm that you are signed in with an account that has editing access to the workbook. Also check the target worksheet’s protection status before you run or modify the Office Script.

Solution 1Recommended

Check workbook permissions, worksheet protection, and used range before running addTable

Use this first because AccessDenied is often caused by missing edit permissions, a protected worksheet, or an invalid used range rather than by the script syntax.

AccessDenied can appear even when the worksheet is not visibly protected. Office Scripts run in the context of the signed-in account, so workbook edit permission, sheet protection, and the actual used range must all be valid before the addTable call.

1
Confirm edit access in Excel for the web

Open the affected workbook in Excel for the web, select File > Info, and verify that the signed-in account is listed as Can edit or Owner. If the workbook is read-only, select Edit Workbook or ask the owner for edit access.

2
Unprotect the target worksheet

Go to the Review tab, click Unprotect Sheet if it is visible, and enter the password if prompted. If the sheet is protected, addTable can read but usually cannot create a table.

3
Validate the used range has headers

In the target worksheet, press Ctrl+End to locate the last used cell and confirm the used range contains a header row with contiguous tabular data. Empty or single-cell ranges can make addTable fail.

4
Run the guarded script

Use the worksheet method directly: first get the sheet, get the used range, throw an error if there is no range, then call sheet.addTable(range, true) and set the table name.

Check workbook permissions, worksheet protection, and used range before running addTable
Expected result: The script creates the table without AccessDenied when the account has edit access, the sheet is unprotected, and the used range is valid.
Free Microsoft Office alternative

Use WPS Office as a Free Alternative for Everyday Spreadsheet Work

Office Scripts are a Microsoft Excel for the web automation feature, and WPS Office does not directly fix Excel Office Script AccessDenied errors. For everyday spreadsheet tasks, WPS Office is a free, lightweight Microsoft Office alternative with a familiar interface and strong Excel format compatibility for opening, editing, and saving .xlsx files.

Free to download and use for everyday spreadsheet workOpens and saves .xlsx files with Microsoft Excel format compatibilityLightweight and familiar ribbon interface eases migration from ExcelAvoids Office Script permission issues for common table and data tasks
microsoft office alternative - wps office

Frequently Asked Questions

Why does my Office Script addTable fail with AccessDenied even if the worksheet is not protected?

The error can also be caused by workbook permission, a used range that is empty or invalid, an existing overlapping table, or a temporary Excel for the web or Office Script service issue. Check edit access, remove sheet protection, verify the range returns a header row, and test in a new workbook.

How do I check whether an Excel worksheet is protected before running an Office Script?

Open the workbook in Excel for the web, select the target worksheet, and go to the Review tab. If Unprotect Sheet is visible, the sheet is protected; click Unprotect Sheet and enter the password if required.

Can an existing table cause the addTable AccessDenied error?

Yes. Excel does not allow overlapping tables, so if the used range already intersects an existing table, the addTable call can fail. Select the range, open the Table Design tab, and convert the existing table to a range before rerunning the script.

How can I tell whether the AccessDenied error is related to the workbook or to Excel services?

Create a blank workbook, add a small header row, and run a minimal addTable script under the same account. If it succeeds, the original workbook or range is the cause; if it fails in multiple accounts and machines, the issue may be a temporary service condition.

Does WPS Office run Excel Office Scripts?

No, WPS Office does not run Excel Office Scripts. However, it opens and edits .xlsx workbooks and is a free, lightweight alternative for common spreadsheet tasks that do not require Office Script automation.