Thread: [Solved] Format text automatically
View Single Post
 
Old 04-20-2013, 01:25 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
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 dexter30,

The only practical way to do that is with a macro. Try:
Code:
Sub Demo()
With ActiveDocument.Content
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "^13DO[S ]{1,2}VEREADOR*^13DO[S ]{1,2}VEREADOR"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True
    .Execute
  End With
  Do While .Find.Found
    .End = .Start + InStrRev(.Text, vbCr) - 2
    .Start = .Start + 1
    .Start = .Start + InStr(.Text, vbCr)
    .Text = Replace(.Text, vbCr, " ")
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
End Sub
Notes: The FIND is case-sensitive; if there are any of your other 'Nš [0-9]{1;8}' strings between the 'DO(S) VEREADOR(A/ES)' ranges, they'll be merged with the surrounding 'DO(S) VEREADOR(A/ES)' ranges; and the last 'DO(S) VEREADOR(A/ES)' range in the document won't be processed.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote