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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Unable to password pro...
Power Automate
Answered

Unable to password protect excel file.

(0) ShareShare
ReportReport
Posted on by 40

For the last year+ I have a flow that uses the UI automation to click file > info > protect workbook > encrypt with password. It has always worked unless I interrupted it. Until today, now it cannot find the elements and is throwing an error. My attempts to refresh the elements or use a menu/list under form filing also did not work.

 

is there another way to accomplish this? Has anyone else ran into similar issues lately?

 

I have another issue in a web automation where before it would run in the background allowing me to work on other things now it errors out if I try to do anything else on the system. 

 

It seems the FLOWS are getting less automation friendly lately.  

I have the same question (0)
  • jogden Profile Picture
    40 on at

    I did find a work around using the send keys TAB ENTER ARROW DOWN ENTER from the file > info tab. Its a dirty solution but it worked.

  • Nived_Nambiar Profile Picture
    18,136 Super User 2026 Season 1 on at

    Hi @jogden 

     

    Below Powershell script will help you to lock an excel file with password

     

     

    # Define the path to the Excel file
    $filePath = "%excel_file%"

    # Define the password you want to use
    $password = "%password%"

    # Create an Excel object
    $excel = New-Object -ComObject Excel.Application

    # Open the Excel file
    $workbook = $excel.Workbooks.Open($filePath)

    # Set the password to protect the workbook
    $workbook.Password = $password

    # Save and close the workbook
    $workbook.Save()
    $workbook.Close()

    # Quit Excel
    $excel.Quit()

    # Release the Excel object from memory
    [System.Runtime.Interopservices.Marshal]::ReleaseComObject($excel) | Out-Null

     

     

     

    here i have passed two variables from power automate desktop , one is %excel_file% which stores the excel file path second is %password% which stores the password by which we need to protect the excel file, you can create both variables with values 

     

    I have created a demo using the above powershell script like above 🙂

     

    Nived_Nambiar_0-1679129540596.png

     

    Kindly like and mark the answer as solution if it help you 🙂

     

     

  • kinuasa Profile Picture
    797 Most Valuable Professional on at

    Hi,
    It would be easy to set the password using the 'Run VBScript' action as shown below.

     

    GetObject("C:\Test\Excel\SampleBook.xlsx").Password = "pass"

     

    Regards,
    kinuasa

     

    *Below is a sample code. Please copy and paste to use.

    SET PassWord TO $'''pass'''
    SET WorkbookFilePath TO $'''C:\\Test\\Excel\\SampleBook.xlsx'''
    Excel.LaunchExcel.LaunchAndOpenUnderExistingProcess Path: WorkbookFilePath Visible: True ReadOnly: False Instance=> ExcelInstance
    Scripting.RunVBScript VBScriptCode: $'''GetObject(\"%WorkbookFilePath%\").Password = \"%PassWord%\"''' ScriptOutput=> VBScriptOutput
    Excel.CloseExcel.CloseAndSave Instance: ExcelInstance
  • Nived_Nambiar Profile Picture
    18,136 Super User 2026 Season 1 on at

    Thank you @kinuasa  for sharing this 🙂

  • jogden Profile Picture
    40 on at

    Can these be executed before saving the file? This FLOW creates the file populates the report password protects and then saves the file to a shared location. I understand the VBA script can be ran after it is saved but can it be done before?  

  • Verified answer
    Nived_Nambiar Profile Picture
    18,136 Super User 2026 Season 1 on at

    Hi @jogden 

     

    First of all sorry for late response.

     

    You can try this powershell script

     

    # Get the Excel Application object for the running instance
    $excel = [System.Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")

    # Get the active workbook
    $workbook = $excel.ActiveWorkbook

    # Set the password for the workbook
    $password = ConvertTo-SecureString "%pwd%" -AsPlainText -Force
    $workbook.Password = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($password))

     

    This powershell script take the active excel and set password to it. here %pwd% is the variable from powerautomate which stores the password by which we need to lock excel file.

     

     

    Sample flow

     

    Nived_Nambiar_0-1679803185587.png

     

    Note: Before running make sure that there is no other excel files are running in the machine , otherwise it may not work

     

    Hope it helps

    Mark it as solution if it resolves your query

     

  • jogden Profile Picture
    40 on at
    Sorry I got sidetracked on a different project. Just came back to this today. This worked thanks!

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 605

#2
Valantis Profile Picture

Valantis 340

#3
11manish Profile Picture

11manish 284

Last 30 days Overall leaderboard