Skip to content

Instantly share code, notes, and snippets.

@githubyouser
Created January 31, 2023 14:21
Show Gist options
  • Save githubyouser/4a9a5ab9f32680b16c73fbd28181bac9 to your computer and use it in GitHub Desktop.
Save githubyouser/4a9a5ab9f32680b16c73fbd28181bac9 to your computer and use it in GitHub Desktop.
Word VBA: Find shaded text and replace with underlining
'https://www.msofficeforums.com/word-vba/49481-remove-shading-specific-color-document-multiple-shading.html
Sub Macro5()
Dim iCol As Long
iCol = Selection.Shading.BackgroundPatternColor
With ActiveDocument.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.ParagraphFormat.Shading.BackgroundPatternColor = iCol
.Replacement.Font.Underline = wdUnderlineSingle
.Execute Replace:=wdReplaceAll
End With
End Sub
@githubyouser
Copy link
Author

To use this script, select the whole paragraph with the particular shading that you want to replace and then run the script. It will find all other paragraphs with the same shading and add underlining to them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment