Hi,
Your file is being used by excel so you cannot remove it. Why not just invoke the save() method?
## - Create an Excel Application instance:
$xlsObj = New-Object -ComObject Excel.Application;
## - Create new Workbook and Sheet (Visible = 1 / 0 not visible)
$xlsObj.Visible = 0;
$workbook = $xlsObj.Workbooks.Open($filename1)
$workbook.ActiveSheet.Cells.Item(1,4) = ""
$workbook.ActiveSheet.Cells.Item(1,10) = ""
$xlsObj.ActiveWorkbook.Save()
## Quit Excel and Terminate Excel Application process:
$xlsObj.Quit();
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($xlsObj)
Stop-Process -Name "EXCEL"
Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.