Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-30-2023, 12:14 AM
reza98 reza98 is offline How to write a "replace" order in VBA working every other time Windows 10 How to write a "replace" order in VBA working every other time Office 2019
Novice
How to write a "replace" order in VBA working every other time
 
Join Date: Jan 2023
Posts: 1
reza98 is on a distinguished road
Question 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.
Reply With Quote
  #2  
Old 01-30-2023, 01:14 AM
Guessed's Avatar
Guessed Guessed is offline How to write a "replace" order in VBA working every other time Windows 10 How to write a "replace" order in VBA working every other time Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
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

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
Reply With Quote
  #3  
Old 01-30-2023, 01:56 AM
gmayor's Avatar
gmayor gmayor is offline How to write a "replace" order in VBA working every other time Windows 10 How to write a "replace" order in VBA working every other time Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,101
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

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
Reply With Quote
Reply

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
How to write a "replace" order in VBA working every other time Add a period of time to a referenced "Time" cell? derelyth Excel 4 03-27-2011 04:31 PM

Other Forums: Access Forums

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