Thread: [Solved] Delete specific text
View Single Post
 
Old 01-02-2012, 03:56 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,465
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

hi Jackson,

Try:
Code:
Sub DeleteH7Text()
Application.ScreenUpdating = False
Dim Rng As Range
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = ""
    .Style = "Heading 7"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute
  End With
  Do While .Find.Found
    Set Rng = .Paragraphs(1).Range.Duplicate
    With Rng
      On Error GoTo ParaLast
      Do
       Select Case .Paragraphs.Last.Next.Style
        Case "Heading 1", "Heading 2", "Heading 3", "Heading 4", "Heading 5", "Heading 6"
          Exit Do
        Case Else
          .MoveEnd wdParagraph, 1
        End Select
      Loop
ParaLast:
      .Delete
    End With
    .Find.Execute
  Loop
End With
Application.ScreenUpdating = True
End Sub
Note: As before, if you're using 'MM Topic ' Styles and note 'Heading ' Styles, you'll need to make the corresponding changes to the code.

You could use the same basic code for any heading level - simply change the heading # to find, then adjust the list of headings in the 'Case' statement to suit.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote