Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 02-11-2013, 03:26 AM
macropod's Avatar
macropod macropod is offline Replace & case Windows 7 64bit Replace & case 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 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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about Case statement Jennifer Murphy Word VBA 1 01-05-2013 02:30 PM
Replace & case Custom Text Filter for this particular case tinfanide Excel 2 09-13-2011 05:08 AM
Case Sensitive (contains) Selection apolloman Excel 2 07-12-2011 04:50 AM
Replace & case From all UPPER CASE to Proper Case davers Word 1 04-30-2009 12:41 PM
Upper to lower case jd Excel 1 04-28-2006 07:40 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:12 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft