Others

How to Run ROBOCOPY Only When Excel Is Running via Batch File

Bushra ParveenBushra Parveen Oct 12, 2026 868 views

Question details

Execute a ROBOCOPY backup command within a Windows batch file only if the Microsoft Excel application is currently running.

How to Run ROBOCOPY Only When Excel Is Running Using a Batch File
Product
Microsoft Excel
Device & OS
Windows
Scenario
Automating file backups using ROBOCOPY and Task Scheduler while restricting the backup job to only trigger when an Excel instance is active.
Observed behavior
The user requires a batch script condition to detect the EXCEL.EXE process, alongside Task Scheduler configurations that prevent the job from remaining active indefinitely or failing without logs.
Before you start

Ensure you have basic knowledge of creating Windows batch (.bat) files and possess administrative privileges to configure Windows Task Scheduler.

Solution 1Recommended

Create a Conditional Batch File Using TASKLIST

Use the TASKLIST and FIND commands within your script to check for the EXCEL.EXE process before allowing ROBOCOPY to execute.

Windows batch scripts can use system commands to check active processes. By filtering the active tasks for EXCEL.EXE, you can set a condition that only triggers your ROBOCOPY command if the process is found.

1
Open a text editor

Open Notepad or your preferred text editor to begin creating your batch script.

2
Add the TASKLIST check

Type the command: TASKLIST /FI "IMAGENAME eq excel.exe" | find /i "excel.exe" > nul. This silently checks if Excel is currently running in the background.

3
Add the conditional ROBOCOPY command

On the next line, evaluate the error level by typing: IF %ERRORLEVEL% EQU 0 (ROBOCOPY "C:\SourceFolder" "D:\BackupFolder" /MIR). Replace the source and destination paths with your actual directories.

4
Save as a batch file

Go to File > Save As, choose 'All Files' from the dropdown, and save the document as 'excel_backup.bat'.

Create a Conditional Batch File Using TASKLIST
Understanding Error Levels: An %ERRORLEVEL% of 0 indicates that the FIND command successfully located EXCEL.EXE. If Excel is not running, the error level will be 1, and ROBOCOPY will be safely skipped.
Free Microsoft Office alternative

Try WPS Office for Your Spreadsheet Needs

While configuring advanced automation for your files, consider managing your spreadsheets with WPS Office. It provides a lightweight, robust, and completely free alternative to Microsoft Office.

  1. 1. Download the Installer: Visit the official WPS Office website and download the free installation package for Windows.
  2. 2. Install WPS Office: Run the downloaded installer and follow the simple on-screen instructions to complete the setup.
  3. 3. Open Your Spreadsheets: Launch WPS Spreadsheets to easily open, edit, and save your existing .xlsx or .xls files without losing formatting.
Completely free and lightweight alternative to Microsoft ExcelSeamlessly compatible with Microsoft Excel formats (.xlsx, .xls, .csv)Familiar tabbed user interface requiring zero learning curveBuilt-in cloud syncing and automatic backup capabilities
microsoft office alternative - wps office

Frequently Asked Questions

Why does my Task Scheduler job remain running indefinitely?

This usually happens when the batch script encounters an error that prompts for user input (like a confirmation prompt), which cannot be seen in the background. Redirecting standard output to a log file (using > log.txt 2>&1) will help you identify the hidden prompt.

Can I use this script to check if WPS Spreadsheets is running instead of Excel?

Yes. To detect WPS Spreadsheets, simply replace 'excel.exe' with 'et.exe' in the TASKLIST command filter within your batch script. The rest of the conditional logic remains identical.

Does TASKLIST check if a specific workbook is open?

No, TASKLIST only checks whether the overall application process (EXCEL.EXE) is active in memory. It cannot determine which specific spreadsheet files are currently open.