Thread: [Solved] Delete specific text
View Single Post
 
Old 01-01-2012, 04:32 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,512
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,

In that case, try:
Code:
Sub DeleteH9Text()
Application.ScreenUpdating = False
Dim Rng As Range
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = ""
    .Style = "Heading 9"
    .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
      While InStr(.Paragraphs.Last.Next.Style, "Heading ") = 0
        .MoveEnd wdParagraph, 1
      Wend
ParaLast:
      .Delete
    End With
    .Find.Execute
  Loop
End With
Application.ScreenUpdating = True
End Sub
This should do the job unless someones created their own Style named 'Heading 10' or something such.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote