Excel file encrypt with password thru Office Scripts

Copper Contributor

Hi all,


I'm trying to automate adding a password to open an Excel file thru Office Scripts but it's being very difficult to me! I can do it with macros (VBA) but because the password must be added in power automate thru a SharePoint site I need to use Office Scripts (because I can't run macros on Excel Online)!


Can anyone help me with the code? I've tried everything... I've even tried chat gpt but the codes he gives me doesn't work! Chat gpt also advised me to use the Actions Record, but on my Windows Excel I don't have that button... the button only shows up for me in Excel online and in Excel online I cant add password encrypt...


Can anyone help me with the code? Or if anyone have the Actions record button in Windows Excel could please someone record the actions of adding a password encrypt to the file and post the code here!


Thank you very much in advance for your time!

4 Replies
best response confirmed by defcrash (Copper Contributor)
I'm afraid the answer is a simple blunt no, cannot be done. Office script cannot "handle files" in any way. It only works on the current document but cannot change things like the document name or encryption.

@Jan Karel Pieterse thats what I was afraid of... :sad_but_relieved_face: Gotta think outside the box now... If anyone knows of any way to password encrypt (or decrypt) an Excel file thru power automate I'll be really appreciated! Thanks again for your time and help!

I'd already seen that one, unfortunately it has to be power automate cloud! :sad_but_relieved_face: I've done an automation on sharepoint/power automate to automatically send some emails with some files, but my company now is enforcing that the Excel files sent to emails outside our organization must be encrypted with password! The purpose was to encrypt the files, send the emails and then decrypt the files again. But I think it will not be possible...