Thread: Delete text
View Single Post
 
Old 12-31-2010, 08:06 PM
macropod's Avatar
macropod macropod is offline Windows 7 32bit Office 2000
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 Michael,

Try:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim strFind As String, strRep As String, i As Integer
strFind = "Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday,morning,afternoon,evening,midnight,"
strFind = strFind & "knots,knots,becoming,north,south,east,west"
strRep = "Mon,Tue,Wed,Thu,fri,Sat,Sun,AM,PM,Evng,Mnght,"
strRep = strRep & "KT,KT,bcmg,N,S,E,W"
With ActiveDocument.Content.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Forward = True
  .Wrap = wdFindContinue
  .Format = False
  .MatchWildcards = True
  .Text = "^13"
  .Replacement.Text = "^l"
  .Execute Replace:=wdReplaceOne
  .Text = "([^13]{2}[!^13]{1,})^13"
  .Replacement.Text = "\1^l"
  .Execute Replace:=wdReplaceAll
  .Text = "Periods*([^13]{2})"
  .Replacement.Text = "\1"
  .Execute Replace:=wdReplaceAll
  .Text = "([ ]{1,})(^13)"
  .Replacement.Text = "\2"
  .Execute Replace:=wdReplaceAll
  .Text = "([!^13])(^13)([!^13])"
  .Replacement.Text = "\1\3"
  .Execute Replace:=wdReplaceAll
  .Text = "([0-9]) to ([0-9])"
  .Replacement.Text = "\1-\2"
  .Execute Replace:=wdReplaceAll
  .MatchWildcards = False
  .MatchCase = False
  For i = 1 To UBound(Split(strFind, ","))
    .Text = Split(strFind, ",")(i)
    .Replacement.Text = Split(strRep, ",")(i)
    .Execute Replace:=wdReplaceAll
  Next
End With
Application.ScreenUpdating = True
End Sub
The macro does the initial F/R you asked for, as well as a bunch of other cleaning up, including the AM/PM changes you mentioned. If you want to process additional words, simply add them and their replacements to the strFind and strRep variables.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]

Last edited by macropod; 12-31-2010 at 08:21 PM. Reason: Added word string array to simplify coding.
Reply With Quote