Permission & Access Issues

Fix Excel VBA FileSystemObject MoveFile Permission Denied for Archived Workbooks

Phi Hung VoPhi Hung Vo Nov 12, 2026 869 views

Question details

The user needs to move processed Excel source workbooks to an archive folder after importing their data, but the VBA FileSystemObject MoveFile operation returns Permission Denied.

Fix Excel VBA FileSystemObject MoveFile Permission Denied for Archived Workbooks
Product
Microsoft Excel VBA with FileSystemObject and Microsoft Access
Device & OS
not provided
Scenario
An automated VBA process opens source workbooks, imports data into Access, creates an export file, closes each workbook, and then archives the processed source file.
Observed behavior
The final fso.MoveFile call fails with a Permission Denied error.
Before you start

Identify the exact source file path and archive destination used by the failing MoveFile statement. Close the workbook manually and verify that the archive folder exists before testing the macro again.

Solution 1Recommended

Release workbook, Access, and file object references before moving the source file

Use this when the source workbook may still be open or held by an Excel, Access, recordset, query, stream, or other VBA object.

Closing a workbook is not always enough if the automation procedure still has active objects that use the file or its imported data. Close applicable objects first, release their references, and then perform the move after cleanup.

1
Close the processed workbook

After data import is complete, use the workbook object's Close method, such as `srcWorkbook.Close SaveChanges:=False`, before calling `fso.MoveFile`.

2
Close Access data objects

Before the move, close any DAO or ADODB recordsets and query-related objects used by the import, for example `rs.Close`, then assign object variables such as `Set rs = Nothing` and `Set qdf = Nothing`.

3
Release file and workbook references

Set workbook, stream, and FileSystemObject-related file references to Nothing after their Close methods run. Ensure no code still refers to the source workbook's FullName, worksheet, or open stream during the move.

4
Move only after cleanup completes

Call `fso.MoveFile sourcePath, archiveFolderPath & "\"` only after the cleanup block has finished and the source file is no longer open by your VBA procedure.

Release workbook, Access, and file object references before moving the source file
Check for external locks: A sync client, antivirus scanner, preview pane, or another user can also lock a workbook. If the macro works after a short delay, investigate software or users accessing the source folder.
Free Microsoft Office alternative

Use WPS Office for lightweight workbook review and file management

This Permission Denied error occurs in a Microsoft Excel and Access VBA automation workflow, so it must be diagnosed in that environment. For everyday workbook review, editing, and organized file handling, WPS Office provides a free, lightweight alternative with a familiar spreadsheet interface and straightforward migration from Microsoft Office files.

Open and edit Excel .xls and .xlsx workbooks with familiar spreadsheet tools.Review processed source workbooks before they enter an archive workflow.Use a lightweight office suite with an interface designed for an easy transition from Microsoft Office.Maintain compatibility with common Microsoft Office spreadsheet formats.
microsoft office alternative - wps office

Frequently Asked Questions

Why does FileSystemObject MoveFile return Permission Denied after I close the workbook?

Another object may still be using the file, such as an Access recordset, query object, text stream, workbook reference, sync client, or antivirus scan. Close applicable objects, set their variables to Nothing, and then run MoveFile.

Does VBA MoveFile overwrite a file already in the archive folder?

No. Build the full destination path and test it with `fso.FileExists(destPath)`. If it exists, rename the incoming file, remove the existing file only when appropriate, or skip the move.

What permissions are required to move an Excel file into an archive folder?

The account running Excel needs access to read the source and create or modify files in the archive folder. Check File Explorer > Properties > Security for the archive folder and, for network locations, verify share permissions as well.

How can I find the exact file that causes the MoveFile error?

Log or display `sourcePath`, `destPath`, `Err.Number`, and `Err.Description` in an error handler surrounding `fso.MoveFile`. The reported paths let you verify the exact source and archive target.

Can an Access import keep a source workbook locked?

It can if the process leaves related recordsets, connections, queries, or automation objects open. Close and release every data object after importing, then move the workbook only after the cleanup code finishes.