View Single Post
 
Old 01-14-2020, 02:05 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
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 of
Default

It might make more sense to have just one bookmark (or a content control) to receive the text then loop through the check boxes and fill the bookmark with the text associated with the bookmarks that are checked. This is easier to follow if you use the default names for the checkboxes e.g as follows. Note the checkbox and bookmark names are case sensitive.


Code:
Private Sub CommandButton1_Click()
Dim oCTRL As Control
Dim sText As String: sText = ""
    Hide
    For Each oCTRL In Controls
        Select Case oCTRL.Name
            Case Is = "CheckBox1"
                If oCTRL.value = True Then
                    If sText = "" Then
                        sText = "Sentence 1"
                    End If
                End If
            Case Is = "CheckBox2"
                If oCTRL.value = True Then
                    If sText = "" Then
                        sText = "Sentence 2"
                    Else
                        sText = sText & vbCr & "Sentence 2"
                    End If
                End If
            Case Is = "CheckBox3"
                If oCTRL.value = True Then
                    If sText = "" Then
                        sText = "Sentence 3"
                    Else
                        sText = sText & vbCr & "Sentence 3"
                    End If
                End If
            Case Is = "CheckBox4"
                If oCTRL.value = True Then
                    If sText = "" Then
                        sText = "Sentence 4"
                    Else
                        sText = sText & vbCr & "Sentence 4"
                    End If
                End If
            Case Is = "CheckBox5"
                If oCTRL.value = True Then
                    If sText = "" Then
                        sText = "Sentence 5"
                    Else
                        sText = sText & vbCr & "Sentence 5"
                    End If
                End If
            Case Is = "CheckBox6"
                If oCTRL.value = True Then
                    If sText = "" Then
                        sText = "Sentence 6"
                    Else
                        sText = sText & vbCr & "Sentence 6"
                    End If
                End If
            Case Is = "CheckBox7"
                If oCTRL.value = True Then
                    If sText = "" Then
                        sText = "Sentence 7"
                    Else
                        sText = sText & vbCr & "Sentence 2"
                    End If
                End If
            Case Is = "CheckBox8"
                If oCTRL.value = True Then
                    If sText = "" Then
                        sText = "Sentence 8"
                    Else
                        sText = sText & vbCr & "Sentence 8"
                    End If
                End If
            Case Is = "CheckBox9"
                If oCTRL.value = True Then
                    If sText = "" Then
                        sText = "Sentence 9"
                    Else
                        sText = sText & vbCr & "Sentence 9"
                    End If
                End If
        End Select
    Next oCTRL
    'MsgBox sText
    FillBM "BookMark_Name", sText
    Unload Me
End Sub

You can then fill the bookmarks with the following function
Code:
Public Sub FillBM(strbmName As String, strValue As String)
'Graham Mayor - http://www.gmayor.com
Dim oRng As Range
    With ActiveDocument
        On Error GoTo lbl_Exit
        Set oRng = .Bookmarks(strbmName).Range
        oRng.Text = strValue
        oRng.Bookmarks.Add strbmName
    End With
lbl_Exit:
    Set oRng = 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