All examples that automate Excel through PowerShell start with this line:
PS> $Excel = New-Object -Com Excel.Application
This seems to b
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.
Yes, you can access the COM object via HWND [Window handle] using this WIN32 API (AccessibleObjectFromWindow).
(See a SO post sample here of using this api via C#)
.
You may have to write an assembly in C# and/or manipulate P/Invoke calls via Powershell.
You may give a shot at it & see how it goes.