Это дополнительный вопрос по этой теме: как заменить все вхождения строки в документах Word в папке - это работает отлично.
$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()
В дополнение к тому, что делает этот код, мне необходимо: 1) отслеживать изменения в каждом документе Word 2) добавлять 3 дополнительные строки в код
Это то, что япробовал (и не работает):
$objWord = New-Object -comobject Word.Application
$objWord.Visible = $false
$objWord2 = New-Object -comobject Word.Application
$objWord2.Visible = $false
$list = Get-ChildItem "C:\Users\antoanetage\Desktop\test location\*.*" -
Include *.docx*
foreach($item in $list){
$objDoc = $objWord.Documents.Open($item.FullName,$true)
$objDoc = $objWord2.Documents.Open($item.FullName,$true)
$objSelection = $objWord.Selection
$wdFindContinue = 1
$FindText = "OCC"
$MatchCase = $true
$MatchWholeWord = $true
$MatchWildcards = $False
$MatchSoundsLike = $False
$MatchAllWordForms = $False
$Forward = $True
$Wrap = $wdFindContinue
$Format = $False
$wdReplaceNone = 0
$ReplaceWith = "Programme resource centre"
$wdFindContinue = 1
$ReplaceAll = 2
$objSelection = $objWord2.Selection
$wdFindContinue = 1
$FindText = "Handbook of procedures"
$MatchCase = $true
$MatchWholeWord = $true
$MatchWildcards = $False
$MatchSoundsLike = $False
$MatchAllWordForms = $False
$Forward = $True
$Wrap = $wdFindContinue
$Format = $False
$wdReplaceNone = 0
$ReplaceWith = "Diploma Programme Assessment Procedures"
$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()