Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-23-2016, 06:35 AM
Belleke Belleke is offline Need some vba code to search a word document an replace it if len = 3 Windows 10 Need some vba code to search a word document an replace it if len = 3 Office 2016
Novice
Need some vba code to search a word document an replace it if len = 3
 
Join Date: Oct 2016
Posts: 2
Belleke is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 10-23-2016, 05:01 PM
Guessed's Avatar
Guessed Guessed is offline Need some vba code to search a word document an replace it if len = 3 Windows 10 Need some vba code to search a word document an replace it if len = 3 Office 2013
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #3  
Old 10-23-2016, 09:00 PM
gmayor's Avatar
gmayor gmayor is offline Need some vba code to search a word document an replace it if len = 3 Windows 10 Need some vba code to search a word document an replace it if len = 3 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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.
Reply With Quote
  #4  
Old 10-24-2016, 01:00 AM
Belleke Belleke is offline Need some vba code to search a word document an replace it if len = 3 Windows 10 Need some vba code to search a word document an replace it if len = 3 Office 2016
Novice
Need some vba code to search a word document an replace it if len = 3
 
Join Date: Oct 2016
Posts: 2
Belleke is on a distinguished road
Default

Hello, thank you both for the quick reply.
The code of gmayor does exact what I want.
Problem is solved.
Have a nice day.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need some vba code to search a word document an replace it if len = 3 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
Need some vba code to search a word document an replace it if len = 3 WORD: Rtf and search-replace (regexp/fonts) seteshpl Word 1 09-06-2011 01:35 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:47 AM.


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