#1
|
|||
|
|||
How to write a "replace" order in VBA working every other time
I have a sort of long document with all parentheses toward one side; like (out of stock(. Now I'm wondering how I can write a replace order replacing every other parenthesis. I already know that the replace order is like: Set myRange = ActiveDocument.Content myRange.Find.Execute FindText:="(", _ ReplaceWith:=")", Replace:=wdReplaceAll but unfortunately, I don't know how to apply If i Mod 2 = 0 Then to the code above. |
#2
|
||||
|
||||
You can use the adjoining characters to differentiate them since an opening bracket usually is preceded by a space whilst a closing bracket might have a letter in front or a period after it.
Find (. Replace ). Or with wildcards on Find ([a-z])\( replace \1)
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
||||
|
||||
Answered at Redirecting Please cross post correctly!
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
Tags |
if-statement, replace, vba |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Excel 2003: VBA "Function" causes "#VALUE!" errors after running "insert/delete row" custom macro | Matt C | Excel Programming | 2 | 01-08-2022 06:03 AM |
"Find and Replace" tool leaves out many of the occurrences of what I put in the "find" window | Swarup | Word | 8 | 06-24-2021 08:31 PM |
Find and Replace "^&" no longer working | merryb | Word | 3 | 08-21-2018 04:01 AM |
Replace "comma" with "and" in line of text | audioman | Word VBA | 7 | 01-21-2016 03:11 PM |
Add a period of time to a referenced "Time" cell? | derelyth | Excel | 4 | 03-27-2011 04:31 PM |