Skip to content

Instantly share code, notes, and snippets.

@eugrus
Created July 6, 2024 23:42
Show Gist options
  • Save eugrus/0a00ea39d46714a02b5c271034d9daee to your computer and use it in GitHub Desktop.
Save eugrus/0a00ea39d46714a02b5c271034d9daee to your computer and use it in GitHub Desktop.
param (
[string]$findText,
[string]$replacewithText
)
$msword = [System.Runtime.Interopservices.Marshal]::GetActiveObject("Word.Application")
# https://learn.microsoft.com/ru-ru/office/vba/api/word.find.execute
$MatchCase = $false
$MatchWholeWord = $true
$MatchWildcards = $false
$MatchSoundsLike = $false
$MatchAllWordForms = $false
$Forward = $false # перепроверить
$Wrap = 1 # https://learn.microsoft.com/ru-ru/office/vba/api/word.wdfindwrap
$Format = $false
$Replace = 2 # = wdReplaceAll https://learn.microsoft.com/ru-ru/office/vba/api/word.wdreplace
$doc = $msword.ActiveDocument
$doc.Content.Find.Execute($findText, $MatchCase, $MatchWholeWord, $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap, $Format, $replacewithText, $Replace)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment