Office Scripts: Encrypt an Excel File with a Password Before Saving
Question details
Determine whether Office Scripts can apply an open password or file-level encryption to an Excel workbook before it is saved to SharePoint through Power Automate.
- Product
- Microsoft Excel for the web, Office Scripts, and Power Automate
- Device & OS
- not provided
- Scenario
- The user wants to protect an Excel workbook with a password or encryption before an automated SharePoint save.
- Observed behavior
- Office Scripts cannot add file-level open-password encryption or change workbook encryption and file-name properties. Desktop Excel, VBA, desktop automation, or a separate encryption service is required.
Confirm whether the workbook is processed in Excel for the web or desktop Excel, and identify whether the requirement is an open password, rights management, or another form of file protection. Also check which Power Automate connector or desktop automation method is available in your environment.
Use a supported encryption method outside Office Scripts
Use this approach when the workbook must be encrypted before Power Automate stores it in SharePoint.
Office Scripts can automate workbook content and formatting, but they do not expose file-level encryption or the open-password setting. A supported Power Automate connector, desktop automation flow, or dedicated file-encryption service must perform that operation.
Decide whether the file needs an open password, SharePoint permissions, Microsoft Purview protection, or another encryption method.
In Power Automate, open the flow in Power Automate and add a supported connector or action that can encrypt or protect files; if none is available, use Power Automate for desktop or an approved encryption service.
Use the Excel Online (Business) action to run the Office Script for workbook edits, then pass the resulting file to the encryption-capable desktop flow, connector, or service.
Use the SharePoint Create file or Update file action after encryption, and verify that the stored file requires the expected protection when opened.
Use desktop Excel or VBA for password protection
Use this option when your organization can run desktop Excel and the workbook must receive a native Excel open password.
Use SharePoint or Microsoft 365 access controls instead of file encryption
Use this option when controlling who can access the workbook is sufficient and a native open-password file is not mandatory.
Edit and Protect Excel-Compatible Workbooks with WPS Office
WPS Office is a free, lightweight Microsoft Office alternative with a familiar spreadsheet interface and strong compatibility with Excel workbooks. It supports common XLSX workflows and can help you edit, review, and prepare files for a separate approved encryption or document-management process, although it does not replace Power Automate or SharePoint encryption controls.
- 1. Install WPS Office: Download and install WPS Office, then open the WPS Spreadsheet application.
- 2. Open the Excel workbook: Select Open from the home screen and choose the XLSX or XLS workbook you want to review or edit.
- 3. Review the workbook content: Use the Spreadsheet tools to check formulas, sheets, formatting, and data before sending the file to your approved encryption or SharePoint workflow.
- 4. Save an Excel-compatible copy: Select Menu or File > Save As, choose Excel 2007–365 (*.xlsx) or another required Excel format, and save the prepared workbook.

Frequently Asked Questions
Can an Office Script set an open password on an Excel workbook?
No. Office Scripts cannot apply file-level open-password encryption or change the workbook encryption property. Use desktop Excel, Power Automate for desktop, a supported connector, or an approved encryption service.
Can VBA encrypt a workbook in Excel for the web?
No. VBA requires desktop Excel and cannot run in Excel for the web. A desktop automation process must open Excel, apply encryption, save the workbook, and then upload it to SharePoint.
Can Power Automate encrypt an Excel file after an Office Script runs?
It depends on the connectors and services available in your tenant. Run the Office Script first, then use an encryption-capable connector, desktop flow, or approved file-encryption service before the SharePoint Create file or Update file action.
Can SharePoint permissions replace an Excel open password?
SharePoint permissions control who can access the stored file, but they do not add an Excel open password to the workbook. Use permissions when access control is sufficient, or use a supported encryption method when file-level protection is required.




