How to Delete Excel Files Locked After Editing in Power Automate: 6-Minute Wait Solution

Here’s how to handle an error that occurs when trying to delete Excel files used in Power Automate flows.

スポンサーリンク

Error: “File is locked for sharing…”

Let’s say you have an Excel file with a table like this (sample data):
When you try to delete this file using the “Delete file” action after accessing it in your flow:
You’ll encounter this error:
This issue commonly occurs in scenarios like the one described in this article:
How to Upload Files to SharePoint Document Library Using Power Apps Attachment Control
Here's how to upload files from Power Apps to SharePoint Online (SPO) document libraries.Prerequisites First, create a d...

When you want to:

  1. Upload an Excel file through Power Apps
  2. Process data from its tables
  3. Delete the Excel file at the end of the flow

Not being able to resolve this error can be quite problematic for your automation process.

 

Excel Tables Remain Locked for 6 Minutes After Use in Flow

While searching for a solution, I found this article:
Consumer Privacy Act (CCPA) Opt-Out Icon
Quickly search for answers, join discussions, post questions, and work smarter in your business applications by joining ...

According to the article, when you use an Excel table in your flow, the Excel file remains locked for 6 minutes. Therefore, if you want to delete the file, you need to wait 6 minutes before executing the deletion.

 

Creating a Flow That Waits 6 Minutes Before Deletion

So, I created a flow that deletes the Excel file after waiting for 6 minutes.

First, add a “Do until” action with “Delete file” and “Delay” actions. Set up the left side of the Do Until condition like this:

 outputs('Delete_file_action_name')['statusCode'] 
Set the condition to “is equal to” 200.
Then set the “Delay” action to 6 minutes. Note: Since the lock lasts approximately 6 minutes, you might want to try shorter intervals like 2 or 3 minutes for faster retry attempts if deletion fails. However, I’ll stick with 6 minutes for now.
Next, click on “Configure run after” for the “Delay” action:
Select “has failed” and click “Done” to complete the setup!

Testing the Flow

After running the flow, confirm that both “Create file” and “Get table” actions completed successfully.
Verify that the Excel file was properly created in the document library.
After approximately 6 minutes, the flow completed successfully!
Looking at the details, we can see that the first deletion attempt failed,
But the second deletion attempt after 6 minutes was successful!
And of course, the file was successfully deleted from the document library!

In conclusion, we’ve learned that when you need to delete an Excel file that has been referenced for its tables within the same flow, you must wait 6 minutes before the deletion can be successful.

Related Articles

コメント

Copied title and URL