Thread: [Solved] Mail Merge into Checkbox
View Single Post
 
Old 01-27-2022, 01:06 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,138
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

If you were to use E-Mail Merge Add-in or Merge and Split to merge your document to separate documents and the field was inserted in the merge document as

{ MERGEFIELD IMMUNIZATIONS } Immunizations
then you could run a macro on the fly to replace the value with a check box content control, either checked or not according to the value. e.g.
Code:
Sub FixCheck(oDoc)
Dim oChk As Range
Dim oWord As Range
Dim oCtrl As ContentControl
Dim bVal As Boolean

    Set oChk = oDoc.Range
    With oChk.Find
        Do While .Execute(findText:="Immunizations")
            Set oWord = oChk.Previous.Words.Last
            Select Case LCase(Trim(oWord.Text))
                Case "yes": bVal = True
                Case "no": bVal = False
            End Select
            Set oChk = oWord
            Set oCtrl = oChk.ContentControls.Add
            oCtrl.Range.Text = ""
            With oCtrl
                .Type = wdContentControlCheckBox
                .Title = "Immunizations": .Tag = .Title
                .Checked = bVal
                .LockContentControl = True
            End With
            Exit Do
        Loop
    End With
lbl_Exit:
    Set oChk = Nothing
    Set oWord = Nothing
    Set oCtrl = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote