View Single Post
 
Old 08-08-2023, 05:45 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,137
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

The following should work for you
Code:
    Select Case True
        Case Chbx2 = True And Chbx3 = True And Chbx4 = True And Chbx5 = True And Chbx6 = True
            FillBM "First", "CheckBox2, CheckBox3, CheckBox4, CheckBox5 and CheckBox6"
        Case Chbx2 = True And Chbx3 = False And Chbx4 = True And Chbx5 = False And Chbx6 = True
            FillBM "First", " CheckBox2, CheckBox4 and CheckBox6"
    End Select
The code calls the following sub to write the value to the named bookmark
Code:
Public Sub FillBM(strbmName As String, strValue As String)
'Graham Mayor - https://www.gmayor.com
Dim oRng As Range
    With ActiveDocument
        On Error GoTo lbl_Exit
        If .Bookmarks.Exists(strbmName) = True Then
            Set oRng = .Bookmarks(strbmName).Range
            oRng.Text = strValue
            oRng.Bookmarks.Add strbmName
        End If
    End With
lbl_Exit:
    Set oRng = Nothing
    Exit Sub
End Sub
You might consider using a content control instead of a bookmark as content controls are less likely to be accidentally deleted. The following will write to a titled content control
Code:
Public Sub FillCC(strCCTitle As String, strValue As String, bLock As Boolean)
'Graham Mayor - https://www.gmayor.com - Last updated - 03 Sep 2021
Dim oCC As ContentControl
    On Error GoTo lbl_Exit
    For Each oCC In ActiveDocument.ContentControls
        If oCC.Title = strCCTitle Then
            oCC.LockContents = False
            oCC.Range.Text = strValue
            oCC.LockContentControl = True
            oCC.LockContents = bLock
            Exit For
        End If
    Next oCC
lbl_Exit:
    Set oCC = 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