开发者

Powershell interact with open Excel

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜