View Single Post
 
Old 06-15-2020, 09:13 AM
bsforza bsforza is offline Windows 10 Office 2019
Novice
 
Join Date: Jun 2020
Posts: 1
bsforza is on a distinguished road
Default 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" }
with:
Code:
{ IF {MERGEFIELD "A"} = "Yes", {MERGEFIELD "T"}{MERGEFIELD "F"}}
This is what I've got going already:
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
Reply With Quote