Tutorials/Power Automate/How to Bypass the 'File Is Locked' Error When Using Excel and SharePoint in Power Automate
Power Automateintermediate

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.

NA
Narmer Abader
@narmer · Published June 3, 2026

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.

ComponentDetails
SharePoint libraryCommissionDocs
Excel fileCommissionData.xlsx
Excel tabletblCommissions
Table columnsSalesPerson, Amount, Commission, Status (Pending / Processing / Paid)
SharePoint file columnCommissionStatus (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

  1. Add a Do Until loop after the List rows present in a table action.
  2. Inside the loop, place the Update file property action.
  3. Configure the Run after settings for the update action so that the flow continues whether the action succeeds or fails.
  4. 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:

textDo Until condition
@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.

Time consideration

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

  1. Add a Send an HTTP request to SharePoint action.
  2. Choose the same site and set the method to POST.
  3. Use the following Uri (replace CommissionDocs with your library name and 1 with the actual item ID):
uriREST endpoint to recycle a file
/_api/web/Lists/GetByTitle('CommissionDocs')/GetItemById(1)/recycle
  1. Add a header:

    KeyValue
    Preferbypass-shared-lock
  2. 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.

Use with caution

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

  1. Create a folder named TempProcessing inside the same document library.
  2. After the file property update (or before it), use a Copy file action to duplicate CommissionData.xlsx into TempProcessing.
  3. Use a List rows present in a table action on the copy (point to the new file path).
  4. Process the rows as needed.
  5. Delete the copied file with a Delete file action when done.
  6. 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:

textExtract table ID from filtered array
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

  1. Create two folders: TempProcessing and ProcessedReports.
  2. Copy the original file into TempProcessing.
  3. Use Update a row actions on the copy (or fill in a range).
  4. After all updates are applied, copy the processed file from TempProcessing to ProcessedReports.
  5. Delete the original file or leave it as is.
  6. 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.

Best for fill‑in‑template scenarios

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

SolutionWhen to UseLock Bypassed?File Retained?
1 – Retry loopYou must update properties on the original file.Waits for unlock✅ Yes
2 – Delete with bypass‑shared‑lockYou need to delete the locked file.Ignored by SharePoint❌ No
3 – Read from temp copyYou only need to read rows and then update properties.Never locks original✅ Yes
4 – Write to output folderYou 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