Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Case sensitive replace

Status
Not open for further replies.

weeze2

Technical User
Joined
Jun 18, 2002
Messages
129
Location
DK
Hi. The code below replaces "AAA" with "BBB" in the document.

How can I avoid replacing "aaa" with "BBB"?

I have tried Option Compare Binary but without results. I could not check for lowercase inside the With either.

****************************************************
findx = "AAA"
replacex = "BBB"

Dim rngStory As Range
For Each rngStory In ActiveDocument.StoryRanges
With rngStory.Find
.Text = findx
.Replacement.Text = replacex
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
Next rngStory
****************************************************
 
Code:
.MatchCase = False
 
weeze2,
[tt]Option Compare Binary[/tt] is for the module, not built in methods.

In Word 2003 you can use [tt]MatchCase[/tt] or [tt]MatchByte[/tt].
Code:
findx = "AAA"
replacex = "BBB"
 
Dim rngStory As Range
  For Each rngStory In ActiveDocument.StoryRanges
    With rngStory.Find
      .Text = findx
      [b].MatchCase = True[/b]
      .Replacement.Text = replacex
      .Wrap = wdFindContinue
      .Execute Replace:=wdReplaceAll
    End With
  Next rngStory

Hope this helps,
CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
Thanks, just what I was looking for!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top