Thread: Replace & case
View Single Post
 
Old 02-11-2013, 03:26 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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 Jennifer,

Here's a macro that should free you from the std F/R constraints:
Code:
Sub Demo()
Dim StrRep As String, StrLeft As String, StrRight As String, i As Long
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = InputBox("What is the text to Find")
    .Replacement.Text = ""
    StrRep = InputBox("What is the Replace text")
    StrLeft = Left(StrRep, 1)
    StrRight = Right(StrRep, Len(StrRep) - 1)
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute
  End With
  Do While .Find.Found
    i = i + 1
    With .Duplicate
      If .Words.First = .Sentences(1).Words.First Then
        .Text = UCase(StrLeft) & StrRight
      Else
        .Text = StrLeft & StrRight
      End If
    End With
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
MsgBox i & " instances replaced."
End Sub
Capitalisation of the replacement text remains the same as whatever you input unless it starts a sentence, in which case the first letter is capitalised.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote