View Full Version : word vba code
excel2006
02-23-2012, 07:35 AM
Hi
I am a newbie and would like to know how to do the following:
In a document, I want to locate all instances of
"r." without the quotes BUT include the full stop and change them all
routine
I have tried something like this in the past, but the problem is, it will also change things like
car. to caroutine
which I don't want.
Thx in advance
R
Talis
02-23-2012, 11:52 AM
Sorry. Lost internet connection in middle of reply.
Talis
02-23-2012, 12:04 PM
If there is always a space preceding the r. you want to find use "<space>r." as your search string and replace with "<space>routine"
If there could be a paragraph return or a space preceding the r. then use:
([^13 ])r. as the search string and \1routine as the replace string.
The \1 means use whatever has been found by the part of the search string in round brackets.
If you want it as VBA try:
Sub SimpleReplace()
With ActiveDocument.Range.Find
.ClearFormatting
.MatchWildcards = True
.Text = "([^13 ])r."
.Replacement.ClearFormatting
.Replacement.Text = "\1routine"
.Forward = True
.Execute Replace:=wdReplaceAll
End With
End Sub
macropod
02-23-2012, 11:18 PM
Alternatively, a wildcard Find/Replace, where:
Find = <r.
Replace = routine
And, in vba:
Sub Demo()
With ActiveDocument.Range.Find
.ClearFormatting
.MatchWildcards = True
.Text = "<r."
.Replacement.ClearFormatting
.Replacement.Text = "routine"
.Forward = True
.Execute Replace:=wdReplaceAll
End With
End Sub
excel2006
02-24-2012, 05:06 AM
Thx for your help. It works a treat.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.