VB-AN-IZ
07-01-2017, 04:22 PM
How can I delete all highlighted words from a document? When recording a macro, it came up with this:
Selection.Find.ClearFormatting Selection.Find.Highlight = True
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
End With
Selection.Delete Unit:=wdCharacter, Count:=1
End Sub
...which only deleted one character.
If it matters, the full idea here was to first highlight and extract any words containing capital letters, as previously solved:
http://www.vbaexpress.com/forum/showthread.php?57443-Highlight-All-Words-Containing-Capital-Letters
Sub ScratchMacro() 'A basic Word macro coded by Greg Maxey
Dim oRng As Range
Set oRng = ActiveDocument.Range
With oRng.Find
Do While .Execute(FindText:="[A-Z]*>", MatchWildcards:=True)
oRng.HighlightColorIndex = wdYellow
oRng.Collapse 0
Loop
End With
lbl_Exit:
Exit Sub
End Sub
Thanks!
Selection.Find.ClearFormatting Selection.Find.Highlight = True
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
End With
Selection.Delete Unit:=wdCharacter, Count:=1
End Sub
...which only deleted one character.
If it matters, the full idea here was to first highlight and extract any words containing capital letters, as previously solved:
http://www.vbaexpress.com/forum/showthread.php?57443-Highlight-All-Words-Containing-Capital-Letters
Sub ScratchMacro() 'A basic Word macro coded by Greg Maxey
Dim oRng As Range
Set oRng = ActiveDocument.Range
With oRng.Find
Do While .Execute(FindText:="[A-Z]*>", MatchWildcards:=True)
oRng.HighlightColorIndex = wdYellow
oRng.Collapse 0
Loop
End With
lbl_Exit:
Exit Sub
End Sub
Thanks!