Forum Discussion
Rozz246
Jun 12, 2023Copper Contributor
Excel Automate Script (Add Password)
Hello, I have created a simple Power Query to combine a number of tabs together. I would also like users to be able to refresh when they update data. But I also want to Password Protect the Combi...
JKPieterse
Jun 12, 2023Silver Contributor
Rozz246 That is very simple:
function main(workbook: ExcelScript.Workbook) {
let selectedSheet = workbook.getActiveWorksheet();
// Unprotect sheet Combined List
selectedSheet.getProtection().unprotect("Password");
// Refresh all data connections
workbook.refreshAllDataConnections();
// Protect sheet Combined List. Passwords are not recorded. Add a password below if needed
selectedSheet.getProtection().protect({ allowAutoFilter: false, allowDeleteColumns: false, allowDeleteRows: false,
allowEditObjects: true, allowEditScenarios: true, allowFormatCells: false,
allowFormatColumns: false, allowFormatRows: false, allowInsertColumns: false,
allowInsertHyperlinks: false, allowInsertRows: false, allowPivotTables: false,
allowSort: false, selectionMode: ExcelScript.ProtectionSelectionMode.normal }, "Password");
}