Hi @Disha2023 ,
Yes, this is achievable, without an API or Third Party Connector (a note for @sandeepstw )
If you are doing this for a one time Excel file, you can create the script inside of it and run that.
If this is something repeatable (you want to create a new file, and apply the script to it), then you'll make a little template.
So, it goes like this:
Step 1) In a SharePoint Library (or in OneDrive, doesn't matter, both count as "SharePoint"), Create an Excel template where you can host your script. (Can just be a plain ole' Excel file. I just called mine ExcelScripts so I'd know what I made it for. Has no content.)
Step 2) Create your script inside of your file (click on "Automate", "New Script", paste it in, save, exit. Yep, that easy.)
function main(workbook: ExcelScript.Workbook) {
// Get the current worksheet.
let selectedSheet = workbook.getActiveWorksheet();
//Assign the Sheet1 worksheet to the ws variable
let ws = workbook.getWorksheet("Sheet1");
//Protect worksheet with a password
ws.getProtection().protect({}, "PowerAutomate");
}
"Sheet1" is the name of the Sheet you want to protect. If you have more than one sheet, or want to protect the whole workbook, check out these options:
https://learn.microsoft.com/en-us/javascript/api/office-scripts/excelscript/excelscript.worksheetprotection?view=office-scripts
https://exceloffthegrid.com/office-scripts-workbook-worksheet-protection/
"PowerAutomate" is the password I've chosen for the example.
Step 3) When you are ready to run your flow to apply the script to another Excel file, it will look like this:

Workbook Location, Workbook Library, and Workbook refer to the Excel file that you want to APPLY the script to.
Script Location, Script Library, and Script refer to your Template. You will find that your *.osts file will appear in the same directory as where ever you saved your Template (unless you move the script, of course.)
That's it.
It might look overwhelming, but I'll mention:
- I am not a coder.
- I have never done this before today.
You got this 🙂