![]() |
|
|
|
#1
|
|||
|
|||
|
I have the following text in a document:
Answer A is correct. Answer B is incorrect. Answer C is incorrect. Answer D is incorrect. This is the output that I would like to get with a find and replace code : Answer (A) is correct. Answer (B) is incorrect. Answer (C) is incorrect Answer (D) is correct. I tried to play with the following code given to me but can't get it to work. Find = "([A-Z]).*[Aa]nswer*( is[ in]{1,3}correct.)" Replace = "Answer (\1)\2" Thanks! |
|
#2
|
|||
|
|||
|
Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "Answer [A-D]{1}"
.MatchWildcards = True
While .Execute
With oRng
.MoveStart wdCharacter, 7
.InsertBefore "("
.InsertAfter ")"
.Collapse wdCollapseEnd
End With
Wend
End With
End Sub
|
|
#3
|
|||
|
|||
|
Thanks! Working great!
Just wondering, would you be able to provide me a find/replace wildcard as an alternative? Again, thanks! |
|
#4
|
|||
|
|||
|
Sure. But that is not as much fun ;-)
Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "(Answer) ([A-D]{1})"
.MatchWildcards = True
.Replacement.Text = "\1 (\2)"
.Execute Replace:=wdReplaceAll
End With
End Sub
|
|
#5
|
|||
|
|||
|
I'm happy with this. It is always good to see both codes.
Thanks! Working great! |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Find/Replace Wildcard Needed-Bold & Highlight
|
rsrasc | Word VBA | 3 | 11-11-2014 03:55 PM |
New Find/Replace Wildcard Needed
|
rsrasc | Word VBA | 2 | 11-11-2014 09:46 AM |
Wildcard Find and Replace
|
Ulodesk | Word | 1 | 06-23-2014 10:26 AM |
| Wildcard Find/Replace deletes extra character | Cosmo | Word | 1 | 06-20-2014 08:49 AM |
Need help using WildCard Find & Replace
|
Cayce | Word | 1 | 06-09-2014 04:17 PM |