Advertisement
opexxx

findandreplacestringindocx.ps1

Apr 7th, 2014
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $list = gci "C:\MyDocs" -Include *.docx -Force -recurse
  2. foreach ($foo in $list) {
  3.  
  4. $objWord = New-Object -ComObject word.application
  5. $objWord.Visible = $True
  6.  
  7. $objDoc = $objWord.Documents.Open("$foo")
  8. $objSelection = $objWord.Selection
  9.  
  10. $findtext= "String to Find"
  11. $ReplaceText = "Replace with String"
  12.  
  13. $ReplaceAll = 2
  14. $FindContinue = 1
  15. $MatchFuzzy = $False
  16. $MatchCase = $False
  17. $MatchPhrase = $false
  18. $MatchWholeWord = $True
  19. $MatchWildcards = $True
  20. $MatchSoundsLike = $False
  21. $MatchAllWordForms = $False
  22. $Forward = $True
  23. $Wrap = $FindContinue
  24. $Format = $False
  25.  
  26. $objSelection.Find.execute(
  27.         $FindText,
  28.         $MatchCase,
  29.         $MatchWholeWord,
  30.         $MatchWildcards,
  31.         $MatchSoundsLike,
  32.         $MatchAllWordForms,
  33.         $Forward,
  34.         $Wrap,
  35.         $Format,
  36.         $ReplaceText,
  37.         $ReplaceAll
  38.     )
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement