How to Fix the AccessDenied Error in an Excel Office Script addTable Call
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.

- 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.
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.
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.
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.
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.
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.
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 for an existing or overlapping Excel table before creating a new table
Use this when the AccessDenied error occurs on a worksheet that already contains tables or when a previous script run may have partially created a table.
Test the script in a new workbook to rule out account or service issues
Use this if the script fails even in a workbook that previously worked or in multiple accounts and machines, because the cause may be a temporary Excel or Office Script service issue.
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.

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.




