Controlar alterações no MS Word por meio do script do PowerShell

0

Alguém poderia me ajudar a modificar o script abaixo, para que ele também possa acompanhar as alterações no MS Word? Eu preciso ser capaz de ver onde uma mudança foi feita para garantir que a sentença resultante ainda faça sentido. Este é o script (não meu):

$objWord = New-Object -comobject Word.Application  
$objWord.Visible = $false

$list = Get-ChildItem "c:\users\stefan\test\*.*" -Include *.doc*
foreach($item in $list){
$objDoc = $objWord.Documents.Open($item.FullName,$true)

$objSelection = $objWord.Selection 
$wdFindContinue = 1
$FindText = "Sara" 
$MatchCase = $False 
$MatchWholeWord = $true
$MatchWildcards = $False 
$MatchSoundsLike = $False 
$MatchAllWordForms = $False 
$Forward = $True 
$Wrap = $wdFindContinue 
$Format = $False 
$wdReplaceNone = 0 
$ReplaceWith = "AJMOO" 
$wdFindContinue = 1 
$ReplaceAll = 2

$a = $objSelection.Find.Execute($FindText,$MatchCase,$MatchWholeWord, ' 
$MatchWildcards,$MatchSoundsLike,$MatchAllWordForms,$Forward,' 
$Wrap,$Format,$ReplaceWith,$ReplaceAll) 
$objDoc.Save()
$objDoc.Close()
}
$objWord.Quit()
    
por Densetsu 20.09.2018 / 12:39

1 resposta

0

Tenha paciência comigo enquanto estou fazendo isso da memória, mas isso deve funcionar:

$objWord = New-Object -comobject Word.Application  
$objWord.Visible = $false

$list = Get-ChildItem "c:\users\stefan\test\*.*" -Include *.doc*
foreach($item in $list){
$objDoc = $objWord.Documents.Open($item.FullName,$true)

$objDoc.TrackRevisions = $true 
$objDoc.ShowRevisions = $true 

$objSelection = $objWord.Selection 
$wdFindContinue = 1
$FindText = "Sara" 
$MatchCase = $False 
$MatchWholeWord = $true
$MatchWildcards = $False 
$MatchSoundsLike = $False 
$MatchAllWordForms = $False 
$Forward = $True 
$Wrap = $wdFindContinue 
$Format = $False 
$wdReplaceNone = 0 
$ReplaceWith = "AJMOO" 
$wdFindContinue = 1 
$ReplaceAll = 2

$a = $objSelection.Find.Execute($FindText,$MatchCase,$MatchWholeWord, ' 
$MatchWildcards,$MatchSoundsLike,$MatchAllWordForms,$Forward,' 
$Wrap,$Format,$ReplaceWith,$ReplaceAll) 
$objDoc.Save()
$objDoc.Close()
}
$objWord.Quit()
    
por 20.09.2018 / 13:54