View Single Post
 
Old 12-13-2015, 09:20 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,344
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

Try:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim strAns As String
With ActiveDocument.Range
  While .Tables.Count > 0
    .Tables(1).ConvertToText
  Wend
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Format = False
    .Forward = True
    .MatchWildcards = True
    .Wrap = wdFindContinue
    .Text = "([0-9]{1,}.^t*^13)(*)(ANS:^t*)^t*^13"
    .Replacement.Text = "\1\3^p\2"
    .Execute Replace:=wdReplaceAll
    .Wrap = wdFindStop
    .Text = "(ANS:*)^13"
    .Replacement.Text = "\1"
    .Execute
  End With
  Do While .Find.Found
    strAns = LCase(.Characters.Last.Previous)
    .Text = "ANS: " & .Characters.Last.Previous & vbCr
    Do While Len(Trim(.Paragraphs.Last.Next.Range.Text)) > 1
      If .Paragraphs.Last.Next.Range.Characters.First <> strAns Then
        .Paragraphs.Last.Next.Range.Delete
      Else
        .Paragraphs.Last.Next.Range.Characters.First.Delete
        .Start = .Paragraphs.Last.Range.End
      End If
    Loop
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
  With .Find
    .Wrap = wdFindContinue
    .Execute Replace:=wdReplaceAll
  End With
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote