1

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?

1 Answer 1

4

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

$xl = [Runtime.InteropServices.Marshal]::GetActiveObject('Excel.Application')
$xl.Quit()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.