Hi all,
I hope you are well.
I have a word file with a Rich text content control whose title is "Name", I tried to create a macro to tell whether or not there is data in the Rich text content control.
However, it doesn´t work as it always says that the Content control has data.
Anyone can help me set up this macro so it says “Content control name is empty” when there is no data in it? Or “Content control name has data”
Thanks
Code:
Sub CheckContentControl()
Dim ctnControl As ContentControl
Dim isEmpty As Boolean
Set ctnControl = ActiveDocument.ContentControls("Name")
If ctnControl Is Nothing Then
MsgBox "Content control 'Name' not found.", vbExclamation
Exit Sub
End If
isEmpty = Len(ctnControl.Range.Text) = 0
If isEmpty Then
MsgBox "Content control 'Name' is empty.", vbInformation
Else
MsgBox "Content control 'Name' has data.", vbI
Nformation
End If
End Sub