#1
|
|||
|
|||
Need some vba code to search a word document an replace it if len = 3
First post here,
I have words in a word document like br.99 or br.124 etc but also br. (no numbers behind) I would like to replace br. (if there are no numbers behind) by bread, something like if len= 3 then replace by "bread" Please advice |
#2
|
||||
|
||||
Is the simple br. always followed by a space or a number? If so, you could search for br.[space] and replace that with 'bread'
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
||||
|
||||
Search for br.[!0-9] with the wildcard option set. http://www.gmayor.com/replace_using_wildcards.htm
Code:
Sub Replace_br() Dim orng As Range Set orng = ActiveDocument.Range With orng.Find Do While .Execute(FindText:="br.([!0-9])", ReplaceWith:="bread\1", MatchWildcards:=True) orng.Collapse 0 Loop End With lbl_Exit: Set orng = Nothing Exit Sub End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com Last edited by gmayor; 10-23-2016 at 11:32 PM. |
#4
|
|||
|
|||
Hello, thank you both for the quick reply.
The code of gmayor does exact what I want. Problem is solved. Have a nice day. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
VBA code to compile one document based on multiple search terms | Hoxton118 | Word VBA | 4 | 04-04-2021 06:02 AM |
Search Replace Code | BolligeA1 | Word | 8 | 02-22-2016 12:32 PM |
Search and Replace vba Word 2003 | tariqaleed2 | Word VBA | 9 | 08-19-2014 03:34 AM |
Search and replace/insert HTML code into Master File using tags | dave8555 | Excel | 2 | 02-23-2014 03:51 PM |
WORD: Rtf and search-replace (regexp/fonts) | seteshpl | Word | 1 | 09-06-2011 01:35 AM |