#1
|
|||
|
|||
Find and replace inside strings containing various names
I have a Word document which includes many instances of each of the strings shown below. Of course name1, name2 and name3 are actually individual first names.
name1, name2 name1, name2, name3 I'm looking for a macro which with change each of the above strings to name1 and name2 name1, name2 and name3 Thanks for your help |
#2
|
||||
|
||||
You can do that with a wildcard Find/Replace, where:
Find = ,([!,^13^l]@[^13^l]) Replace = ^32and\1 No vba required.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Almost worked
Thanks for your answer. However, I didn't provide enough information. The document format is:
First Item: some variable information Second Item: more variable information Third Item: still more Fourth Item: even more Fifth Item: name1, name2 (or name1, name2, name3) The above pattern repeats 5 or 10 times in the document. Your code does a great job at inserting the "and" as I requested. However, it also places the "and" in other places in the document, like at the beginning of each new line. I'm going to see if I can work with your suggestion but would appreciate any additional help. |
#4
|
||||
|
||||
It would probably be impossible for a Find/Replace, and even for a macro, to identify with certainty when you do or don't want a particular comma replaced. The Find/Replace works 100% with the sample data you have posted so far. Obviously, though, if you have a sentence like:
First Item: some variable information, but not all there's no way to know the comma's not one you want to replace. I don't see how the F/R could possibly insert 'and' at the beginning of a line, unless that line begins with a comma (which would be quite unusual).
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
It works!!
Thanks for the code. I made a typo when transferring the code you provided. When I corrected my error, it worked beautifully.
Thanks again, I really appreciate your expert help and knowledge. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How To Find Bookmarks and/or custom fields Inside Building Blocks, Office 2010 | thpanos | Word | 3 | 02-17-2013 08:49 AM |
Bad view when using Find and Find & Replace - Word places found string on top line | paulkaye | Word | 4 | 12-06-2011 11:05 PM |
Where we can find a Word document (docx file) that contains professional work inside? | Jamal NUMAN | Word | 0 | 06-26-2011 09:57 AM |
update style of all strings available between two specific strings | vikrantkale | Word | 1 | 03-28-2011 06:13 PM |
find author names in text | anil3b2 | Word | 0 | 08-02-2010 04:12 AM |