在powershell中操作已在运行的excel实例
好的,我打开了一个从powershell启动的Internet Explorer实例的工作簿,使用:在powershell中操作已在运行的excel实例,excel,powershell,Excel,Powershell,好的,我打开了一个从powershell启动的Internet Explorer实例的工作簿,使用: $browser = new-object -ComObject "InternetExplorer.Application" $browser.navigate("url") 我从url下载/打开了工作簿,但我想使用正在运行的脚本对其进行操作。我想知道是否能够从进程id创建一个新的com对象: (Get-Process excel | Where-Object {$_.MainWindow
$browser = new-object -ComObject "InternetExplorer.Application"
$browser.navigate("url")
我从url下载/打开了工作簿,但我想使用正在运行的脚本对其进行操作。我想知道是否能够从进程id创建一个新的com对象:
(Get-Process excel | Where-Object {$_.MainWindowTitle -like "*titleOFdownloadedEXCELwb*"}).id
有人能给我指出正确的方向吗?多谢各位
$xl = [Runtime.Interopservices.Marshal]::GetActiveObject('Excel.Application')
将以活动Excel实例(如果存在)为目标。不要担心获取Excel实例。创建一个Excel.Application实例,它将自动为您提供一个正在运行的实例。将应用程序上的visible设置为true,然后使用app.workbooks集合枚举工作簿并查找您的工作簿感谢您的回复,问题是,工作簿是从浏览器(在临时文件夹中下载)打开的,然后在excel中打开的。如何枚举wb?
$xl=[Runtime.Interopservices.marshall]::GetActiveObject('Excel.Application')
谢谢你,dgorti和@sodawillow,我现在可以开始工作了。