Skip to main content

Notifications

Community site session details

Community site session details

Session Id : Eqz+QrNQlN/fnkcIDEqnhp
Power Automate - Power Automate Desktop
Answered

Power Automate Desktop - protected Excel sheet

Like (0) ShareShare
ReportReport
Posted on 30 Jan 2024 11:46:13 by 6

Hi!

I am using Power Automate for Desktop, and I am not using actions which are referred to Excel. Instead I am using SQL queries, but since the worksheets are protected, I need first to unprotect them to do SQL query, am I right?
Would the VB Script be helpful? If yes, what should I write to enable (unprotect the Sheet)?
I also want to protect the Sheet at the end, how should I do that? With VB Script?

  • Verified answer
    Agnius Bartninkas Profile Picture
    10,045 Most Valuable Professional on 31 Jan 2024 at 14:14:24
    Re: Power Automate Desktop - protected Excel sheet

    Yes, you can use VBScript to unprotect a worksheet or workbook (depending on what's protected). For example, to unprotect an entire workbook, you can use this:

    Set Excel = CreateObject("Excel.Application")
    Set Workbook = Excel.Workbooks.Open("{YourExcelWorkbookPath}")
    Workbook.Unprotect {Password}
    Workbook.Save
    Workbook.Close

     

    Replace the placeholders in curly brackets with actual values.

    If you want to unprotect a single protected worksheet, you would need to use an extra step, such as this:

    Set Excel = CreateObject("Excel.Application")
    Set Workbook = Excel.Workbooks.Open("{YourExcelWorkbookPath}")
    Set Worksheet = Workbook.Worksheets("{WorksheetName}")
    Worksheet.Unprotect {Password}
    Workbook.Save
    Workbook.Close

     

    You would then need to use the exact same procedure with a .Protect method afterwards to protect your workbook/worksheet again after you're done. The .Protect method has more parameters that can be passed, depending on what you want to protect (i.e. how much you want to allow the user to do, if you're only protecting a worksheet and not an entire workbook). See here for reference: https://learn.microsoft.com/en-us/office/vba/api/excel.worksheet.protect

    -------------------------------------------------------------------------
    If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.

    I also provide paid consultancy and development services using Power Automate. If you're interested, DM me and we can discuss it.

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Automate - Power Automate Desktop

#1
eetuRobo Profile Picture

eetuRobo 64 Super User 2025 Season 1

#2
Nived_Nambiar Profile Picture

Nived_Nambiar 18 Super User 2025 Season 1

#3
CU12050101-0 Profile Picture

CU12050101-0 12

Overall leaderboard
Loading started