VBA & Macro Problems

Office Scripts: Encrypt an Excel File with a Password Before Saving

Emma BrownEmma Brown Nov 12, 2026 869 views

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.
Before you start

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.

Solution 1Recommended

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.

1
Identify the required protection

Decide whether the file needs an open password, SharePoint permissions, Microsoft Purview protection, or another encryption method.

2
Choose an encryption-capable action

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.

3
Run Office Scripts before encryption

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.

4
Save the protected file to SharePoint

Use the SharePoint Create file or Update file action after encryption, and verify that the stored file requires the expected protection when opened.

Office Scripts limitation: Office Scripts cannot set an Excel open password, apply file-level encryption, or change workbook file properties such as encryption and file name.
Free Microsoft Office alternative

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. 1. Install WPS Office: Download and install WPS Office, then open the WPS Spreadsheet application.
  2. 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. 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. 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.
Free and lightweight spreadsheet editor for everyday workbook tasksFamiliar interface that makes migration from Excel easierCompatible with Microsoft Excel XLSX and XLS workbook formatsUseful for reviewing and preparing workbooks before a separate protection or automation step
microsoft office alternative - wps office

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.