Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 07-31-2015, 12:33 AM
norgro norgro is offline Find and replace condition Windows XP Find and replace condition Office 2007
Novice
Find and replace condition
 
Join Date: Feb 2013
Location: Perh Australia
Posts: 12
norgro is on a distinguished road
Default Find and replace condition


I want to apply a condition to the replacement.

I want "ea" to be replaced by "2" only when "ea " is not the first or last letters of the word that contains it.

1. How do I apply this condition?
2. How do I get the find and replace to stop when the end of document is reached?

Note: In Braille, the code for "ea" is "2" in a word document.

Help would be greatly appreciated.

Norman

Sub FindAndReplaceEAwith2()
'
' Find and Replace "ea" with "2" Macro
' Macro recorded 31/7/15 by NG
'
On Error GoTo StopMacro
Set oRng = ActiveDocument.Range
oRng.HighlightColorIndex = wdNoHighlight
oRng.Find.ClearFormatting
oRng.Find.Replacement.ClearFormatting
oRng.Find.Replacement.Highlight = True
For i = 1 To 20
With oRng.Find
.Text = "ea"
.Replacement.Text = "2"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
oRng.Find.Execute Replace:=wdReplaceOne
MsgBox (oRng.Characters.First.Previous)
Next i

StopMacro:
Stop

End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find and replace condition VBA Batch Find & Replace for all MSOffice extensions, to replace File Name and Content of the File QA_Compliance_Advisor Word VBA 11 09-11-2014 11:51 PM
Find and replace condition Find what box in Find and replace limits the length of a search term Hoxton118 Word VBA 7 06-10-2014 05:05 AM
Find and replace condition Macro - replace with condition ubns Word VBA 1 05-02-2012 12:52 AM
Find and replace condition Bad view when using Find and Find & Replace - Word places found string on top line paulkaye Word 4 12-06-2011 11:05 PM
Find and replace condition Help with find and replace or query and replace shabbaranks Excel 4 03-19-2011 08:38 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:53 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