Excel File Locked for Editing by a Deleted User: Causes and Workarounds
🔍 WiseChecker

Excel File Locked for Editing by a Deleted User: Causes and Workarounds

You open an Excel file stored on SharePoint or OneDrive and see a message that the file is locked for editing by a user who no longer exists in your organization. This can happen even when the user’s account was deleted weeks ago. The lock persists because SharePoint keeps a temporary file handle or a co-authoring session tied to the former user’s identity. This article explains why the lock does not clear automatically and provides four workarounds you can use to regain access to the file.

Key Takeaways: How to Unlock an Excel File After a User Is Deleted

  • SharePoint site > Library settings > Manage files with no checked in version: Force-check in files left in a checked-out state by a deleted user.
  • OneDrive admin center > User files > Sign out of all sessions: Terminate active sessions for a deleted user that may hold a file lock.
  • SharePoint Online Management Shell cmdlet Remove-SPODeletedSite: Clear orphaned site collections that can contribute to persistent file locks.

ADVERTISEMENT

Why a Deleted User Can Still Lock an Excel File

When a user opens an Excel file in SharePoint or OneDrive, the service creates a temporary lock file with a name like ~$filename.xlsx. This lock file signals to other users that the file is in use. The lock file is normally deleted when the user closes Excel or the browser tab. If the user’s account is deleted while the file is still open, the lock file can remain because the cleanup process associated with that user identity no longer runs.

The lock can also persist if the user had the file checked out in a SharePoint document library. Checking out a file creates an exclusive edit lock that only the checking-out user or a site collection administrator can release. When the user is deleted, the checked-out state remains because no automated process clears it.

A third cause involves co-authoring sessions. SharePoint tracks active editing sessions through WebSocket connections. If a user’s session is not properly terminated — for example, if the browser crashes or the network drops — the session record can survive the account deletion. SharePoint then continues to report the file as locked by the deleted user.

Workarounds to Unlock the Excel File

Use these methods in the order shown. Start with the simplest option and move to the next only if the lock remains.

Workaround 1: Force Check-in the File in SharePoint

  1. Open the SharePoint document library
    Navigate to the site that contains the locked Excel file. Click Documents in the left navigation or open the library where the file is stored.
  2. Enable the Checked Out To column
    If you do not see a Checked Out To column, click the column header area and select Add column > Show/hide columns. Check the box for Checked Out To. This column shows which user has the file checked out.
  3. Locate the file
    Find the Excel file that shows a checked-out icon (a green arrow) in the Type column. The Checked Out To column should show the deleted user’s name.
  4. Force check-in the file
    Hover over the file name, click the three dots (ellipsis), then select More > Check In. In the dialog that appears, enter a comment such as “Force check-in by admin” and click Check In. The file is now available for editing by others.

Workaround 2: Sign Out All Sessions for the Deleted User

  1. Open the OneDrive admin center
    Go to https://admin.onedrive.com and sign in as a global admin or SharePoint admin.
  2. Find the deleted user’s OneDrive
    In the left menu, click User files. Search for the deleted user’s email address or display name. If the user’s OneDrive still exists, click the user name to open their files list.
  3. Sign out all sessions
    At the top of the user files page, click Sign out of all sessions. This terminates any active WebSocket or co-authoring sessions associated with that user.
  4. Wait and retry
    Wait five minutes for the session termination to propagate. Then open the Excel file again. The lock should be cleared.

Workaround 3: Delete the Lock File Manually in SharePoint

  1. Enable viewing of hidden files in SharePoint
    Open the document library, click the gear icon, and select Library settings. Under General settings, click Library advanced settings. Set Show hidden files to Yes and click OK.
  2. Find the lock file
    Return to the library. Look for a file named ~$filename.xlsx where filename is the name of your locked Excel file. This hidden file is the lock file.
  3. Delete the lock file
    Hover over the lock file, click the three dots, and select Delete. Confirm the deletion.
  4. Open the original file
    Try to open the original Excel file. The lock should be gone. After you finish, return to Library settings and set Show hidden files back to No.

Workaround 4: Use SharePoint Online Management Shell to Clear the Lock

  1. Install the SharePoint Online Management Shell
    If you do not have it installed, download the module from the Microsoft Download Center and install it on your computer.
  2. Connect to SharePoint Online
    Open the SharePoint Online Management Shell as an administrator. Run Connect-SPOService -Url https://yourtenant-admin.sharepoint.com and sign in with your admin credentials.
  3. Run the Set-SPOUser cmdlet to remove the lock
    Use the following command, replacing the placeholder values: Set-SPOUser -Site https://yourtenant.sharepoint.com/sites/yoursite -LoginName deleteduser@yourtenant.com -IsSiteCollectionAdmin $false. This command strips any lingering permissions that might hold the lock.
  4. Force remove the user from the site
    Run Remove-SPOUser -Site https://yourtenant.sharepoint.com/sites/yoursite -LoginName deleteduser@yourtenant.com. This removes the user from the site collection’s user list, which often clears the lock.

ADVERTISEMENT

If the Lock Persists After All Workarounds

SharePoint Library Sync Stops After Moving a Folder

If you moved the locked file to a different folder while the deleted user had it open, the lock file may have moved with it. Use Workaround 3 to find and delete the lock file in the new folder location. If the file was moved via a sync client, stop the sync, delete the lock file from the SharePoint web interface, and then restart the sync.

Excel File Shows Locked by a User Who Never Opened It

This can happen when a co-authoring session is inherited from a parent folder or when a sharing link was used. Check the file’s sharing permissions in SharePoint. Click the file, select Details, and review the Sharing section. Remove any sharing links that include the deleted user. Then use Workaround 2 to sign out all sessions for that user.

File Locked by a Deleted User in a Synced Folder

If you use OneDrive sync or SharePoint sync, the lock file may exist on your local machine. Close Excel and any Office apps. Open File Explorer, navigate to the synced folder, and enable viewing of hidden files. Delete any ~$ files that match the locked Excel file. Then open the file from the web interface to confirm the lock is gone.

Comparison of Workarounds for a Deleted User Lock

Item Force Check-in Sign Out Sessions Delete Lock File PowerShell
Required permission Site owner or member with edit rights Global admin or SharePoint admin Site owner or member with edit rights SharePoint admin
Time to complete 2 minutes 5 minutes 3 minutes 10 minutes
Affects other users No No No Yes, removes user from site
Works for checked-out files Yes No No No
Works for co-authoring locks No Yes Yes Yes

You can now unlock an Excel file locked by a deleted user using one of four workarounds. Start with the force check-in method if the file shows a checked-out state. If the lock is from a co-authoring session, sign out all sessions for the deleted user in the OneDrive admin center. For persistent locks, consider using the SharePoint Online Management Shell to remove the user from the site collection entirely. As an advanced tip, enable the SharePoint auditing feature to track future lock events and identify the source of locks before deleting a user account.

ADVERTISEMENT