logo
search
OneDrive File Issues

Fix VBA Save to OneDrive Creating Extra Random Files

Maira MehtabMaira Mehtab Sep 20, 2026 869 views

Question details

Running a VBA script to save an Excel workbook to a OneDrive folder and then back to its original path results in the creation of multiple randomly named temporary files.

Product
Microsoft Excel, OneDrive
Device & OS
not provided
Scenario
Executing VBA SaveAs procedures to duplicate or back up workbooks within a OneDrive-synchronized directory.
Observed behavior
The VBA macro generates additional files with random names instead of updating the intended workbook seamlessly, likely due to sync conflicts or file locking.
Before you start

Before modifying your VBA code, ensure that your OneDrive desktop client is fully updated and temporarily pause syncing to see if the issue persists without network interference.

Solution 1Recommended

Optimize VBA SaveAs Code for Synchronized Folders

Prevent OneDrive from creating conflict files by adjusting how and when the VBA script saves the workbook.

When VBA triggers a SaveAs command in a OneDrive folder, the sync engine immediately tries to upload the file. If a subsequent save occurs before the upload completes, OneDrive creates a temporary or randomly named file to prevent data loss.

1
Pause between saves

Introduce an Application.Wait command in your VBA code to pause execution for a few seconds between the save to OneDrive and the save to the original path.

2
Disable AutoSave during execution

Add 'ActiveWorkbook.AutoSaveOn = False' at the start of your macro and re-enable it at the end to prevent background saves from interfering.

3
Save to a local folder first

Modify your VBA script to save the backup to a local, non-synced folder, then use the FileCopy command to move it to the OneDrive directory.

Free Microsoft Office alternative

Experience Stable Spreadsheet Editing with WPS Office

If you frequently encounter synchronization errors, temporary file bugs, or VBA conflicts in Microsoft Excel, consider switching to WPS Office. It provides a lightweight, highly compatible environment for managing spreadsheets without unnecessary background sync interruptions.

  1. 1. Download and Install: Get the free WPS Office suite from the official website and install it on your PC.
  2. 2. Open Your Workbook: Launch WPS Spreadsheets and open your macro-enabled file directly.
  3. 3. Run Macros Securely: Enable macros in the Developer tab and execute your VBA scripts without OneDrive sync conflicts.
Highly compatible with Microsoft Excel (.xlsx, .xls, .xlsm) formats.Advanced support for VBA and macro execution in WPS Spreadsheets.Lightweight installation with faster load times and smoother file saving.Built-in, stable cloud backup options that prevent file duplication.
microsoft office alternative - wps office

Frequently Asked Questions

Why does Excel VBA create temporary files with random names?

When Excel saves a file, it typically creates a temporary file first, deletes the original, and then renames the temporary file. If a background process like OneDrive syncs or locks the temporary file before the renaming process finishes, the temporary file gets left behind.

Can I use VBA to pause my script until OneDrive finishes syncing?

VBA cannot directly read OneDrive's sync status. However, you can use the Application.Wait method to pause the script for a few seconds, giving OneDrive enough time to process the file before executing the next SaveAs command.

How do I prevent AutoSave from interfering with VBA macros?

You can disable AutoSave temporarily during your macro execution by adding ActiveWorkbook.AutoSaveOn = False at the beginning of your script. Remember to set it back to True at the end of the procedure.