Skip to content

Instantly share code, notes, and snippets.

@eugrus
Created September 3, 2025 11:56
Show Gist options
  • Save eugrus/3d1f996fc02bc1ba54d3309928522111 to your computer and use it in GitHub Desktop.
Save eugrus/3d1f996fc02bc1ba54d3309928522111 to your computer and use it in GitHub Desktop.
remove highlights & shading from the active document in Word
$word = [Runtime.Interopservices.Marshal]::GetActiveObject("Word.Application")
$doc = $word.ActiveDocument
if ($doc) {
# Clear highlights & shading
foreach ($r in $doc.StoryRanges) {
do {
$r.HighlightColorIndex = [Microsoft.Office.Interop.Word.WdColorIndex]::wdNoHighlight
$r.Shading.BackgroundPatternColor = [Microsoft.Office.Interop.Word.WdColor]::wdColorAutomatic
$r = $r.NextStoryRange
} while ($r)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment