【发布时间】:2017-03-01 09:42:49
【问题描述】:
我必须通过数千个文档来寻找一个字符串。当我这样做时,word文档会在屏幕上弹出,然后在删除对象后消失。
Documents.OpenNoRepairDialog 方法的参数在位置 13 处,用于控制可见性。除了代码中列出的 3 个参数之外,我无法获得任何组合。有没有办法在代码运行并将我的屏幕变成闪光灯时使这些文档不可见?
$Doc = $Word.Documents.OpenNoRepairDialog($file,$false,$true) 是我需要帮助的部分。尝试添加更多参数(例如 $null)时出现错误。
$Word = New-Object -comobject Word.Application
$Word.Visible = $false
$word.DisplayAlerts = "wdAlertsNone"
$Doc = $Null
$DocContent = $Null
$Doc = $Word.Documents.OpenNoRepairDialog($file,$false,$true)
$DocContent = $Doc.Content.Text | Select-String -Pattern $Using:SearchStrings
If($DocContent)
{
Write-Verbose "Match in $_ for Word" -Verbose
Write-Output "Match in $_" | Out-File -FilePath $Using:OutputFilePath -Append
}
Else
{
Write-Verbose "No Match" -Verbose
}
$Word.Documents.Close()
$Word.Quit()
While([System.Runtime.InteropServices.Marshal]::ReleaseComObject($DocContent)){}
While([System.Runtime.InteropServices.Marshal]::ReleaseComObject($Doc)){}
While([System.Runtime.InteropServices.Marshal]::ReleaseComObject($Word)){}
Remove-Variable -Name DocContent
Remove-Variable -Name Doc
Remove-Variable -Name Word
【问题讨论】:
标签: .net powershell ms-word