Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim i As Long, StrTxt As String
StrTxt = "Conditional Text"
With ThisDocument
For i = 1 To .ContentControls.Count
If ContentControls(i).Title = "Chk1" Then
If ContentControls(i).Checked = False Then StrTxt = " "
Exit For
End If
Next
For i = 1 To .ContentControls.Count
With ContentControls(i)
If .Title = "Txt1" Then
.LockContents = False
.Range.Font.Hidden = False
.Range.Text = StrTxt
If StrTxt = " " Then
.Range.Font.Hidden = True
End If
.LockContents = True
Exit For
End If
End With
Next
End With
End Sub
Ordinarily, I do. An oversight last time. A more efficient version appears below.Hi Paul,
thanks for your code. Please, next time wrap it in CODE tags so it is easier to read, thank you
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim i As Long, StrTxt As String
StrTxt = "Conditional Text"
With ThisDocument
If ContentControl.Title = "Chk1" Then
If ContentControl.Checked = False Then StrTxt = " "
End If
For i = 1 To .ContentControls.Count
With ContentControls(i)
If .Title = "Txt1" Then
.LockContents = False
.Range.Font.Hidden = False
.Range.Text = StrTxt
If StrTxt = " " Then .Range.Font.Hidden = True
.LockContents = True
Exit For
End If
End With
Next
End With
End Sub