What would be the appropriate PowerShell cmdlet to use to kill a specific Excel file. The command
Stop-Process -Name "excel"
closes all open Excel applications.
Thanks in advance!
Actually, excel opens .xlsx files in one instance of excel.exe
Kill the excel.exe will kill all opening workbooks. The MainWindowTitle only shows the active workbook, so you will not able to match passive workbooks by the property.
A better way to close a specific workbook is to acquire the excel instance by com object.
Close the workbook matched the Name (file name) or FullName (file path)
$excel = [System.Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
$excel.DisplayAlerts = $false
$excel.Workbooks | %{if($_.Name -imatch "excel file name"){$_.Close()}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With