#1
|
|||
|
|||
Replace all occurrences of one merge field with plain text
I have a very large Word 2007 mail merge doc with several dozen data fields, one of which is repeated over 300 times throughout the doc (it's a training guide, if you're curious). I'd like to replace that one field - all 300+ times - with plain text, just remove the field entirely and have a typed text string in its place. Can someone give me a push in the right direction? I can't quite figure out what to put in the "Find what" and "Replace with" boxes in the Find/Replace dialog. Is it even possible to "zap" fields in this manner using Find/Replace?
Thanks! |
#2
|
||||
|
||||
Hi blankenhorst,
You could use a macro like: Code:
Sub Demo() Dim oFld As Field For Each oFld In ActiveDocument.Fields With oFld If .Type = wdFieldMergeField Then If Trim(Replace(Replace(.Code, "MERGEFIELD", ""), Chr(34), "")) = "MyFieldName" Then .Unlink End If End With Next End Sub Code:
Sub Demo() Dim oFld As Field For Each oFld In ActiveDocument.Fields With oFld If .Type = wdFieldMergeField Then If Trim(Replace(Replace(.Code, "MERGEFIELD", ""), Chr(34), "")) = "MyFieldName" Then .Code.Text = "QUOTE " & Chr(34) & "My Text" & Chr(34) .Update .Unlink End If End If End With Next End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Thank you, Paul
So it appears that this is a feature that does not natively exist in Word, which seems odd. After all, there is a way to replace all occurrences of a static text string with a field. Is there no way to do the reverse except writing a custom macro?
|
#4
|
|||
|
|||
Thanks again, Paul
Wrote the macro and ran it. Works like a magic wand. Thanks!
|
#5
|
||||
|
||||
Hi blankenhorst,
With Find/Replace, with field codes displayed (eg by pressing Alt-F9), using ^d as the Find expression will find any field. That might do if the mergefields you want to replace are the only fields in the document, but not otherwise. PS: You shouldn't need to re-type the macro - copy/paste should do.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#6
|
|||
|
|||
Thank you, macropod. I didn't know about the ^d thing. But yeah, since I have several dozen merge fields, and I only want to flatten all of the occurrences of one field, I'll have to stick with the macro for now. However, I appreciate the reply.
|
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Html send as plain text | JosSchaars | Outlook | 5 | 12-21-2010 02:51 PM |
Selecting merge field based on whether or not text is present | amym | Mail Merge | 1 | 12-07-2010 05:14 AM |
Replace All with plain text containing subscript | DeaducK | Word | 0 | 06-24-2010 08:16 PM |
merge field formatting problem with "text to be inserted before" | wissam | Mail Merge | 0 | 12-13-2009 12:50 AM |
Text field after word merge in Word 2000 | brianlb | Word | 1 | 06-29-2009 07:50 AM |