0

Could someone please help me modify the script below, so that it can also track changes in MS Word? I need to be able to see where a change was made in order to ensure the sentence that resulted will still make sense. This is the script (not mine):

$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()
Densetsu
  • 1
  • 3
  • I don't think somebody here will want to program for you. Actually you should try by yourself, and then come with a specific question in case you have a problem. – davidbaumann Sep 20 '18 at 10:42
  • I tried, and I cannot even find a place to look for a direction, in which to do my research. If you have a constructive tip about that, I will very much appreciate it. I have googled it for hours already. – Densetsu Sep 20 '18 at 10:44
  • In VBA, Word publishes the [Revisions Object](https://docs.microsoft.com/en-us/office/vba/api/word.revisions). I don't know if it also exists in PowerShell. – harrymc Sep 20 '18 at 11:59

1 Answers1

0

Bear with me as I'm doing this from memory but this should do the trick:

$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()
motosubatsu
  • 570
  • 2
  • 11