1

Using powershell can I kill/force close a single window (excel workbook) running under Excel without killing the whole process which closes all excel workbooks running under that same process instance? I can search for processes named Excel, and check if the window title contains "myworksheet.xlsx" and then kill the process. But if there were any other workbooks open under the same process then those also get killed:

Get-Process | Where-Object {($_.ProcessName -eq "Excel") -and ($_.MainWindowTitle -match "TeamWorkbook.xlsx")} | Stop-Process -Force

The background is simply that my group uses a spreadsheet which is only writable by one person at a time. Occasionally someone leaves it open on their computer and they go away and then no one else can write to the spreadsheet.

  • Try fighting it from a different angle. Create a vba macro in excel, one that saves and closes the file gracefully. Store the macro in the personal.xls on every users machine. Trigger it to run remotely via powershell using the excel comobject. Easier said than done, but very plausible to close only a specific workbook without affecting the others. Or just use MS Access, that's really what's called for in this situation. – Knuckle-Dragger Aug 6 '15 at 0:18
  • Thanks for your suggestion. I'm not familiar with visual basic for office. Considering the small number of times my scenario occurs I believe learning vba would be too much of a time investment. Thanks – WallLeaf Aug 13 '15 at 13:37
0

The short answer is no, there is no way that you can only close one document now if we can close the whole program then we have a lot of options.

The only thing you could do is delete the lock file on the workbook and then someone else can edit it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.