Troubleshooting “The process cannot access the file because it is being used by another process.”

This error occurs when Power Query or Excel attempts to read, transform, or overwrite a local file that an active operating system thread has locked. Windows enforces file-locking rules: if another application, or a hidden background instance of Excel, holds an exclusive open handle on a source CSV, XLSX, or text file, Power Query cannot access it during data refresh.

Quick Answer

Close any software currently accessing the source file, including hidden background instances of Excel in Task Manager. If the source file is stored in a synced directory like OneDrive or Dropbox, pause file synchronization during refresh. If the query reads from the active workbook itself, separate the data into an external file or use local Excel Tables.


What Causes the File Lock

Operating systems prevent data corruption by placing write-locks or shared-read locks on active files. When Power Query refreshes, its background mashup engine (safe_m_engine.exe or Microsoft.Mashup.Container.exe) requests read access. If another program opened the file without allowing shared reads, the operating system denies the container’s request.

The four most frequent sources of file locks are:

  1. Self-referencing workbooks: Power Query is set up to read an Excel file from disk via Excel.Workbook(File.Contents("...")), but that exact file is currently open in your active Excel session.
  2. Orphaned Excel processes: Excel was previously closed, but a hung background process (EXCEL.EXE) still retains a lock on the file.
  3. Cloud sync engines: Services like OneDrive, SharePoint Sync, Google Drive, or Dropbox are uploading a modified version of the source file at the exact moment Power Query tries to pull data.
  4. Antivirus scanning or preview panes: Windows Explorer’s Preview Pane or endpoint security scanners are scanning the file handle.

Progressive Diagnostic and Repair Steps

1. Check for Orphaned Processes

Even if Excel appears closed on your desktop, a crash or poorly terminated macro can leave an active instance running in the background.

  1. Press Ctrl + Shift + Esc to open Task Manager.
  2. Select the Details tab.
  3. Look for any instances of EXCEL.EXE or Microsoft.Mashup.Container.exe.
  4. Right-click the process and choose End Task.
  5. Reopen your reporting workbook and refresh the query.
2. Resolve Self-Referencing Workbook Locks

A frequent mistake occurs when building a query that imports data from the very workbook running the query using File.Contents. When you refresh the query, Excel attempts to connect to the saved copy on disk while holding an open read/write handle on it.

  • The Fix: If the query must pull from the active workbook, do not use File.Contents(). Instead, format your source data as a structured Excel table and import it directly into Power Query using:
    This reads the in-memory data stream without querying the disk-bound file handle. Excel.CurrentWorkbook(){[Name="YourTableName"]}[Content]
3. Handle Cloud Sync and File Conflicts

When source files live inside a synchronized folder (OneDrive, SharePoint Sync, or Box), the sync engine locks files while uploading changes.

4. Turn Off the Windows Explorer Preview Pane

Windows Explorer locks files while generating visual previews.

  1. Open File Explorer.
  2. Go to the View tab.
  3. Toggle off Preview pane and Details pane.
  4. Attempt the Power Query refresh again.
5. Identify the Locking Handle with Sysinternals Process Explorer

If the locking application remains unknown:

  1. Download Microsoft’s free Process Explorer (part of Sysinternals).
  2. Run the program as Administrator.
  3. Press Ctrl + F and paste the full file name of your source data.
  4. Click Search. The bottom pane will show the exact process name and PID holding the handle.
  5. Close or terminate that application.

What to Do Next

If eliminating locks restores connectivity on single queries but errors recur whenever you run a full model update, your queries may be competing for the same file in parallel. Switch from global refresh to sequential execution by reviewing Using the “Refresh All” button vs. Individual Query Refresh: Conflict resolution.