Track changes in MS Word through PowerShell script

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

Posted 2018-09-20T10:39:05.193

Reputation: 1

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 – 2018-09-20T10:42:14.027

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 – 2018-09-20T10:44:10.553

In VBA, Word publishes the Revisions Object. I don't know if it also exists in PowerShell.

– harrymc – 2018-09-20T11:59:10.643

Answers

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

Posted 2018-09-20T10:39:05.193

Reputation: 510

@Densetsu Glad it worked :) – motosubatsu – 2018-09-21T11:29:15.927