Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-11-2014, 06:10 AM
rsrasc rsrasc is offline Find/Replace Wildcard Needed Windows 7 64bit Find/Replace Wildcard Needed Office 2010 64bit
Competent Performer
Find/Replace Wildcard Needed
 
Join Date: Mar 2014
Location: Germany
Posts: 148
rsrasc is on a distinguished road
Default Find/Replace Wildcard Needed

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!
Reply With Quote
  #2  
Old 11-11-2014, 06:47 AM
gmaxey gmaxey is offline Find/Replace Wildcard Needed Windows 7 32bit Find/Replace Wildcard Needed Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,440
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 11-11-2014, 07:44 AM
rsrasc rsrasc is offline Find/Replace Wildcard Needed Windows 7 64bit Find/Replace Wildcard Needed Office 2010 64bit
Competent Performer
Find/Replace Wildcard Needed
 
Join Date: Mar 2014
Location: Germany
Posts: 148
rsrasc is on a distinguished road
Default

Thanks! Working great!

Just wondering, would you be able to provide me a find/replace wildcard as an alternative?

Again, thanks!
Reply With Quote
  #4  
Old 11-11-2014, 07:58 AM
gmaxey gmaxey is offline Find/Replace Wildcard Needed Windows 7 32bit Find/Replace Wildcard Needed Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,440
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #5  
Old 11-11-2014, 08:28 AM
rsrasc rsrasc is offline Find/Replace Wildcard Needed Windows 7 64bit Find/Replace Wildcard Needed Office 2010 64bit
Competent Performer
Find/Replace Wildcard Needed
 
Join Date: Mar 2014
Location: Germany
Posts: 148
rsrasc is on a distinguished road
Default

I'm happy with this. It is always good to see both codes.


Thanks! Working great!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find/Replace Wildcard Needed Find/Replace Wildcard Needed-Bold & Highlight rsrasc Word VBA 3 11-11-2014 03:55 PM
Find/Replace Wildcard Needed New Find/Replace Wildcard Needed rsrasc Word VBA 2 11-11-2014 09:46 AM
Find/Replace Wildcard Needed 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
Find/Replace Wildcard Needed Need help using WildCard Find & Replace Cayce Word 1 06-09-2014 04:17 PM

Other Forums: Access Forums

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