References‎ > ‎

Macro to delete grey

Sub AutoDeleteGray()
'
' AutoDeleteGray Macro
'
'
'
' deleteParagraph Macro
'
'
Dim length As Integer
Dim backPos As Integer
p = Selection.Paragraphs.First
Last = Selection.Paragraphs.First

Do While Selection.Characters.First.HighlightColorIndex = wdGray25
    If (Selection.MoveRight <> 1) Then Exit Do
Loop


Do While Last = p
length = 0

    If (Selection.Characters.First.HighlightColorIndex = wdGray25) Then
        
        Do While Selection.Characters.First.HighlightColorIndex = wdGray25
            length = length + 1
            If Selection.MoveLeft <> 1 Then Exit Do
            
        Loop
        
        If Selection.Characters.First.HighlightColorIndex <> wdGray25 Then
            Selection.MoveRight
            backPos = backPos - 1
        End If
        Selection.Delete Unit:=wdCharacter, Count:=length
    End If
    If (Selection.MoveLeft <> 1) Then Exit Do
    Last = Selection.Paragraphs.First
    backPos = backPos + 1
Loop

Selection.Move Unit:=wdCharacter, Count:=backPos

End Sub

Comments