Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-15-2020, 09:13 AM
bsforza bsforza is offline Replace Merge Field with Conditional If Windows 10 Replace Merge Field with Conditional If Office 2019
Novice
Replace Merge Field with Conditional If
 
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
  #2  
Old 06-16-2020, 01:17 AM
macropod's Avatar
macropod macropod is offline Replace Merge Field with Conditional If Windows 7 64bit Replace Merge Field with Conditional If Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 20,434
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

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
[MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Replace Merge Field with Conditional If Replace specific word inside a table in the Header with Merge field Turin74 Word VBA 3 06-06-2019 06:17 PM
Replace Merge Field with Conditional If Form with conditional field. Asuryan33 Word VBA 6 10-18-2017 03:45 PM
Replace Merge Field with Conditional If Conditional Field CKTisdale Word 1 04-10-2015 02:41 PM
Replace Merge Field with Conditional If Conditional merge fields in mail merge Aude Mail Merge 1 01-06-2012 07:38 PM
Replace Merge Field with Conditional If Replace all occurrences of one merge field with plain text blankenthorst Mail Merge 5 07-01-2011 05:18 AM

Other Forums: Access Forums - Senior Forums

All times are GMT -7. The time now is 03:26 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2020 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft