May 30 2023 03:01 PM
I am using excel scripts. My challenge is to remove protection from a password protected worksheet, apply changes, then re-apply password protection. I'd be grateful for help with the portions of the script that disables the password, unprotects the worksheet, then later in the same script, re-applies the protection and re-applies the password.
May 30 2023 04:48 PM - edited May 31 2023 08:04 AM
@Bkkendig Here is a sample I did:
/**
* This script filters table.
*/
function main(workbook: ExcelScript.Workbook) {
//Unlock worksheet
let wksht = workbook.getActiveWorksheet()
wksht.getProtection().unprotect()
//Get table
let tbl = workbook.getTable("PRs")
console.log(tbl.getRowCount())
// Sort the table based on the first column.
if ( tbl.getAutoFilter().getIsDataFiltered() ) {
tbl.clearFilters()
} else {
tbl.getColumn(6).getFilter().applyValuesFilter([""]);
}
wksht.getProtection().protect()
}
this script Unlocks the sheet, then toggles a filter on column 6 on/off, then ReLocks the sheet
May 31 2023 08:00 AM
May 31 2023 08:02 AM - edited May 31 2023 08:05 AM
Yes look at lines 6,7,17
I edited above comment to indicate that it unlocks the sheet, THEN toggles, then Relocks the sheet