Forum Discussion
TaurusGear13
Dec 26, 2025Copper Contributor
Unprotect in Office Scripts
I am writing an office script that requires sorting on a sheet with the overall sheet protected and specific cells not protected. I need to be able to sort an unprotected range using an automation bu...
SergeiBaklan
Dec 26, 2025Diamond Contributor
You may use this ExcelScript.WorksheetProtection interface - Office Scripts | Microsoft Learn interface. Didn't use it before, tested right now on
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
const protection: ExcelScript.WorksheetProtection = sheet.getProtection()
protection.pauseProtection()
sheet.getRange("C7:I39")
.getSort()
.apply(
[{ key: 0, ascending: true }]
, false
, false
, ExcelScript.SortOrientation.rows
)
protection.resumeProtection()
}It works with me, but only with Excel for web, not in desktop version. Didn't check with password, but it shall work, please check documentaion.