How to save and stop MS Office process with powershell? -


i need close word/excel/powerpoint documents taskbar powershell script. stop-process kills process doesnt save changes made. need save , close document. able word following script:

$wd = [runtime.interopservices.marshal]::getactiveobject('word.application') $wd.documents | % { $_.close() } get-process | ?{$_.processname -eq "winword"} | stop-process 

when same excel , powerpoint error message , changes not saved. excel have done follows:

$excel = [runtime.interopservices.marshal]::getactiveobject('excel.application') $excel.activeworkbook | % { $_.close() } get-process | ?{$_.processname -eq "excel"} | stop-process 

for powerpoint:

$ppt= [runtime.interopservices.marshal]::getactiveobject('powerpoint.application') $ppt.presentations | % { $_.close() } get-process | ?{$_.processname -eq "powerpoint"} | stop-process 

error displayed is:

+             $excel.activeworkbook | % { $_.close() } +                                         ~~~~~~~~~~     + categoryinfo          : invalidoperation: (close:string) [], runtimeexception     + fullyqualifiederrorid : methodnotfound 

try code:

$excel.displayalerts = $false; $excel.workbooks | % { $_.save(); $_.close() } 

Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -