Fix Excel VBA FileSystemObject MoveFile Permission Denied for Archived Workbooks
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.

- 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.
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.
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.
After data import is complete, use the workbook object's Close method, such as `srcWorkbook.Close SaveChanges:=False`, before calling `fso.MoveFile`.
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`.
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.
Call `fso.MoveFile sourcePath, archiveFolderPath & "\"` only after the cleanup block has finished and the source file is no longer open by your VBA procedure.

Verify archive folder access and handle an existing destination file
Use this when the source file is closed but the archive location may be unavailable, protected, or already contain the same file name.
Add error logging around the VBA MoveFile statement
Use this when the cause is unclear and you need the exact file paths and VBA error details from the failing run.
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.

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.




