开发者

Powershell interact with open Excel

开发者 https://www.devze.com 2022-12-30 05:10 出处:网络
To interact with excel in Powershell it is common to start a new excel as follows: $x = New-Object -comobject Excel.Application

To interact with excel in Powershell it is common to start a new excel as follows:

$x = New-Object -comobject Excel.Application

Instead of that I have an open Excel开发者_运维技巧 process already. (I get it as follows)

$excelprocess = Get-Process | Where-Object {$_.name -eq "excel"} | Sort-Object -Property "Starttime" -descending | Select-Object -First 1

Is there a way to interact with this specific excel process over PS?


You want to use the Marshal.GetActiveObject method e.g.:

$xl = [Runtime.InteropServices.Marshal]::GetActiveObject('Excel.Application')
$xl.Quit()
0

精彩评论

暂无评论...
验证码 换一张
取 消