web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Power Automate - Power Automate Desktop
Suggested answer

Excel Protected workbook

(0) ShareShare
ReportReport
Posted on by 6
Does anyone know if there is a way that the following can be done?
 
I have an excel attachment that comes via email to my flow that now has a password protection.  I need to know if there is a way remove this in the flow.  Thanks
Categories:
I have the same question (0)
  • mmbr1606 Profile Picture
    14,453 Super User 2025 Season 2 on at
    Excel Protected workbook
    hey
     
     
    what is the intention of the flow? please clarify
  • SM-17110845-0 Profile Picture
    6 on at
    Excel Protected workbook
    to save email received from a shared email as an attachement (password protected) to update an existing table in sharepoint - this happens daily.  Then once a month the updated document in sharepoint is to be sent out to business via email but has to also be password protected.
  • Suggested answer
    rzaneti Profile Picture
    4,182 Super User 2025 Season 2 on at
    Excel Protected workbook
     
     
    If your organization doesn't restrict its usage, you can go with Office Scripts for this task. You can either unlock an entire workbook, or some individual worksheets (as long as you have the passwords, of course).
     
    I'm sharing some blogs that I posted about Office Scripts, so you can have more context about it, but as a short description, it works like a VBA for Excel on the Web and it can be initialized by Power Automate:
    - Sending values from Power Automate to Excel with Office Scripts: https://digitalmill.net/2024/01/17/sending-values-from-power-automate-to-excel-with-office-scripts/
    - Debugging and accessing Office Scripts outputs with console.log: https://digitalmill.net/2024/09/09/debugging-and-accessing-office-scripts-outputs-with-console-log/
     
    First thing to do is to create your Script, which will look like this. Go to Automate tab and click New script:
     
     
    Then you can enter your script in the side pane:
     
    - You can use the code in line 5 to unprotect a workbook, just including the password between the parenthesis (in yellow).
    - You can use the code in line 7 to unprotect a worksheet, just including the sheet name (in green) and the password (in yellow) between the parenthesis. If you want to unprotect more than one worksheet, just copy/paste the same line, changing the sheet name and the password.
    - You can then use the lines 11 and 12 to protect it again, in the same or in other script, depending on your needs. For protecting the worksheet, you can use some custom settings as described here: https://learn.microsoft.com/en-us/javascript/api/office-scripts/excelscript/excelscript.worksheetprotection?view=office-scripts
     
    
    function main(workbook: ExcelScript.Workbook) {
    
    
        workbook.getProtection().unprotect('123') //Unprotect workbook
    
        workbook.getWorksheet('Sheet1').getProtection().unprotect('123') //Unprotect worksheet
    
    
        //PROTECTING AGAIN
        workbook.getProtection().protect('123')
        workbook.getWorksheet('Sheet1').getProtection().protect(null, '123')
    
    }
    
     
    After saving the Script, go to Power Automate and add a Run Script action, informing the file where you want to run it and the script to be used. In your case, since you're working with an email attachment, you will first need to save it to SharePoint or OneDrive:
     
     
    You can even pass dynamic values from PA to Office Scripts, following the instructions from the "Sending values from Power Automate to Excel with Office Scripts" blog, mentioned above. 
     
    Let me know if it works for you or if you need any additional help!
     
    If this solved your issue, please mark it as Accepted Answer.
    👍 If it helped, feel free to give it a like!

    🌐 Explore more Power Platform content on my Website or on my ▶️ YouTube
    💼 Find me on LinkedIn

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Coming soon: forum hierarchy changes

In our never-ending quest to improve we are simplifying the forum hierarchy…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 555 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 388 Moderator

#3
chiaraalina Profile Picture

chiaraalina 264

Last 30 days Overall leaderboard