Yes, there are a few ways to kill all instances of Excel in Power Automate Desktop, ranging from built-in actions to command-line approaches. The most robust methods will forcefully terminate the processes.
Important Warning: "Killing" a process means it will be terminated immediately without saving any unsaved work. Use these methods with caution, especially in production environments.
Here are the common methods:
Method 1: Using the "Terminate Process" Action (Recommended for Simplicity)
This is the most straightforward PAD-native way.
-
Search for Action: In the Actions pane, search for "Terminate process".
-
Drag and Drop: Drag the "Terminate process" action into your flow.
-
Configure:
- Specify process by: Select "Process name".
- Process name: Enter
EXCEL.EXE
- PAD will attempt to terminate all processes matching this name.
[image: PAD Terminate Process] open
-
Error Handling (Optional but Recommended):
- If no Excel instances are running, this action might throw an error.
- You can wrap this action in an "On block error" action to handle cases where Excel isn't running, or use a "Label" and "Go to" for a simpler error jump if needed.
- Alternatively, you can first use "Get processes" to check if "EXCEL.EXE" is running before attempting to terminate.
Method 2: Using "Run DOS Command" with taskkill (More Forceful)
This method uses the Windows taskkill command, which is very effective.
-
Search for Action: Search for "Run DOS command".
-
Drag and Drop: Drag the "Run DOS command" action into your flow.
-
Configure:
- DOS command:
taskkill /F /IM EXCEL.EXE
/F: Forcefully terminates the process.
/IM: Specifies the image name (process name).
- Working folder: You can usually leave this as default or set it to
%SystemRoot%\System32%.
- Uncheck "Wait for command to complete" if you don't need to wait, but it's usually fine to leave it checked.
[image: PAD Run DOS Command] open
-
Output (Optional):
- The
DOSCommandOutput variable will contain the output from the command (e.g., "SUCCESS: The process "EXCEL.EXE" with PID xxxx has been terminated.").
- The
ExitCode variable will be 0 on success. If it says "ERROR: The process "EXCEL.EXE" not found.", it means no Excel was running.
Method 3: Using "Run PowerShell Script" (Alternative to DOS Command)
PowerShell offers a similar capability.
-
Search for Action: Search for "Run PowerShell script".
-
Drag and Drop: Drag the "Run PowerShell script" action into your flow.
-
Configure:
- PowerShell script to run:
Stop-Process -Name Excel -Force -ErrorAction SilentlyContinue
Stop-Process -Name Excel: Stops all processes named "Excel".
-Force: Forcefully terminates.
-ErrorAction SilentlyContinue: Prevents an error from stopping the PAD flow if no Excel processes are found.
[image: PAD Run PowerShell Script] open
-
Output (Optional):
- The
PowershellOutput variable will contain any output from the script.
- The
ScriptError variable will contain any errors (though SilentlyContinue should suppress most).
Choosing the Right Method:
- "Terminate Process" Action: Easiest and most "PAD-native." It should work for most cases.
- "Run DOS Command" with
taskkill: Very robust and offers the /F (force) flag explicitly. Good if "Terminate Process" sometimes fails on a stubborn Excel instance.
- "Run PowerShell Script" with
Stop-Process: Similar to taskkill but uses PowerShell. Also very robust. The -ErrorAction SilentlyContinue is convenient for avoiding flow errors if Excel isn't running.
Recommendation:
Start with the "Terminate Process" action. If you find it doesn't always work (e.g., Excel is completely frozen), then try the "Run DOS Command" with taskkill or "Run PowerShell Script" methods, as they are generally more forceful.
Remember to add these steps at the beginning of your flow if you need a clean environment, or at the end for cleanup. And always warn users about potential data loss!