How to Bypass the 'File Is Locked' Error When Using Excel and SharePoint in Power Automate
When a flow reads an Excel table and then updates SharePoint file properties, the file remains locked. Here are four independent approaches to work around it—no magic, just smart automation design.
If you have ever built a Power Automate flow that reads rows from an Excel table and then updates SharePoint file properties, you have probably seen this error: “File <filename> is locked for shared use by <user email>”.
The culprit is an internal lock that Excel Online places on the file while a flow action (like List rows present in a table) is still running. When the next action tries to modify the same file’s properties, SharePoint refuses because the file is “in use”. The lock can last up to 10 minutes after the Excel action completes.
This article presents four workarounds, each with a different trade‑off. We will use a sample automation for Sales Commission Processing to illustrate the solutions.
| Component | Details |
|---|---|
| SharePoint library | CommissionDocs |
| Excel file | CommissionData.xlsx |
| Excel table | tblCommissions |
| Table columns | SalesPerson, Amount, Commission, Status (Pending / Processing / Paid) |
| SharePoint file column | CommissionStatus (choice: Pending, Processing, Paid) |
The flow reads the table rows, performs some calculation (or a simple approval), and then tries to update the CommissionStatus property of the Excel file. This is where the lock error occurs.
Solution 1 – Loop Until the Lock Releases
The simplest approach: when the file is locked, wait a few seconds and try again. The Excel lock is automatically removed a few seconds to minutes after the last Excel action finishes.
Implementation steps
- Add a Do Until loop after the List rows present in a table action.
- Inside the loop, place the Update file property action.
- Configure the Run after settings for the update action so that the flow continues whether the action succeeds or fails.
- Add a Condition to check whether the update action returned HTTP status code 400 (the locked‑file error).
Do Until: @equals(outputs('Update_file_property')?['statusCode'], 400) != true
Update file property
Condition: is the statusCode 400?
Yes: Delay 30 seconds → return to Do Until
No: (exit loop)
The expression inside the Do Until limit settings should be:
@not(equals(outputs('Update_file_property')?['statusCode'], 400))How it works If the file is locked, the update action fails with 400, the condition triggers a 30‑second delay, and the loop repeats. Once the lock is gone, the update succeeds and the condition is false, ending the loop.
The loop can run many times, especially if the lock persists for several minutes. Add a reasonable timeout (e.g., 5 minutes) in the Do Until configuration to avoid infinite loops.
Solution 2 – Delete a Locked File with the Bypass‑Shared‑Lock Header
If your flow needs to delete a locked Excel file (for example, after successfully processing the rows), you can tell SharePoint to ignore the lock by sending the Prefer: bypass-shared-lock header in a REST API call.
Implementation steps
- Add a Send an HTTP request to SharePoint action.
- Choose the same site and set the method to POST.
- Use the following Uri (replace
CommissionDocswith your library name and1with the actual item ID):
/_api/web/Lists/GetByTitle('CommissionDocs')/GetItemById(1)/recycle-
Add a header:
Key Value Prefer bypass-shared-lock -
Optionally, send an empty body.
How it works
The Prefer: bypass-shared-lock header tells SharePoint to skip the shared‑use check and recycle the file immediately.
This solution is only suitable when your flow’s goal is to remove the file (e.g., after archiving). It does not help if you need to keep the file and update its properties.
Solution 3 – Read File Rows Without Touching the Original
Instead of reading directly from the locked file, you can copy the file to a temporary folder, read the copy, and then delete the copy. This completely avoids the lock because the original file is never touched by Excel actions.
Implementation steps
- Create a folder named TempProcessing inside the same document library.
- After the file property update (or before it), use a Copy file action to duplicate
CommissionData.xlsxinto TempProcessing. - Use a List rows present in a table action on the copy (point to the new file path).
- Process the rows as needed.
- Delete the copied file with a Delete file action when done.
- Finally, update the property on the original file – now the first Excel action is long finished and the lock is gone.
Getting the table ID on the copied file The List rows action requires a table ID. Use an expression to retrieve it from the table name:
first(body('Filter_array:_Name_eq_tblCommissions'))?['id']This assumes you have a Filter array action that filters the List tables output for the table named tblCommissions.
Result The original file is never read by an Excel action, so it never becomes locked. The property update that follows will succeed.
Solution 4 – Write to a Separate Output Folder
This is a variation of solution 3, ideal when you need to update the Excel file itself (e.g., fill in a template) and then keep the result. Instead of modifying the original file, you copy the file to a temp folder, apply updates there, and then move the updated file to a final output folder.
Implementation steps
- Create two folders: TempProcessing and ProcessedReports.
- Copy the original file into TempProcessing.
- Use Update a row actions on the copy (or fill in a range).
- After all updates are applied, copy the processed file from TempProcessing to ProcessedReports.
- Delete the original file or leave it as is.
- Delete the temporary copy.
How it works The original file remains untouched by Excel actions, so no lock ever occurs. The final output is a brand‑new file in the ProcessedReports folder.
If your flow needs to populate an Excel template and then deliver the completed file to a different location, this pattern keeps your original template safe and avoids lock conflicts.
Comparison of Solutions
| Solution | When to Use | Lock Bypassed? | File Retained? |
|---|---|---|---|
| 1 – Retry loop | You must update properties on the original file. | Waits for unlock | ✅ Yes |
| 2 – Delete with bypass‑shared‑lock | You need to delete the locked file. | Ignored by SharePoint | ❌ No |
| 3 – Read from temp copy | You only need to read rows and then update properties. | Never locks original | ✅ Yes |
| 4 – Write to output folder | You need to modify the Excel content and deliver a new file. | Never locks original | ✅ Yes (new) |
Common Mistakes & Troubleshooting
-
Forgetting to configure Run after settings. If the Update file property action fails and the flow stops, the Do Until loop will never retry. Always set “is successful” and “has failed” as run‑after options for the action inside the loop.
-
Using the wrong item ID in the REST call. The URI expects the SharePoint item ID (not the file name). Use the Get file metadata action to obtain it.
-
Not deleting temporary files. Files left in the TempProcessing folder can accumulate and consume storage. Add a Delete file action after they are no longer needed.
-
Expressions containing bare angle brackets. In Power Automate expressions, avoid
<and>unless they are inside quotes. Use@{...}syntax correctly.
Final Recommendation
If your workflow can tolerate a small delay, Solution 1 (retry loop) is the easiest to implement and keeps your file intact. For scenarios where you process and archive, Solution 3 or 4 (copy to temp) are more reliable because they never cause a lock to begin with. Solution 2 should be reserved strictly for cleanup tasks that require bypassing the lock to delete a file.
Choose the approach that fits the rest of your automation’s logic. And remember—the lock is a safety feature, not a bug. Working around it intelligently makes your flows both robust and maintainable.
References
- Original article by Matthew Devaney: 4 Solutions For Excel File Is Locked Error In Power Automate
- Microsoft documentation on SharePoint REST API headers (Prefer: bypass-shared-lock): Manage file locks with the SharePoint REST API (placeholder – verify exact URL)
- Power Automate documentation: Configure run after settings