How to connect to existing instance of Excel from PowerShell?

前端 未结 2 1888
既然无缘
既然无缘 2020-12-07 02:44

All examples that automate Excel through PowerShell start with this line:

PS> $Excel = New-Object -Com Excel.Application

This seems to b

2条回答
  •  春和景丽
    2020-12-07 02:55

    Instead of the usual New-Object -ComObject excel.application us this

    $excel = [Runtime.Interopservices.Marshal]::GetActiveObject('Excel.Application')

    Rest stays the same.

    One downside. You will only get the excel "instances" started by the same user that will initiate the ps1.

提交回复
热议问题