#1
|
|||
|
|||
Replace Merge Field with Conditional If
Hi, I'm having some trouble figuring out how to replace a basic Merge field with a conditional statement. I'm looking to, using macros, replace something like:
Code:
{ MERGEFIELD "A" } Code:
{ IF {MERGEFIELD "A"} = "Yes", {MERGEFIELD "T"}{MERGEFIELD "F"}} Code:
Sub Ex() Dim oFld As Field For Each oFld In ActiveDocument.Fields With oFld If .Type = wdFieldMergeField Then If Trim(Replace(Replace(.Code, "MERGEFIELD", ""), Chr(34), "")) = "A" Then // Replace Merge Field with Conditional - Help .Update End If End If End With Next End Sub |
#2
|
||||
|
||||
Why are you trying to change the mailmerge main document via VBA rather than making the change in the document itself? This would, after all, be a once-off change.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Replace specific word inside a table in the Header with Merge field | Turin74 | Word VBA | 3 | 06-06-2019 06:17 PM |
Form with conditional field. | Asuryan33 | Word VBA | 6 | 10-18-2017 03:45 PM |
Conditional Field | CKTisdale | Word | 1 | 04-10-2015 02:41 PM |
Conditional merge fields in mail merge | Aude | Mail Merge | 1 | 01-06-2012 07:38 PM |
Replace all occurrences of one merge field with plain text | blankenthorst | Mail Merge | 5 | 07-01-2011 05:18 AM |