View Single Post
 
Old 01-18-2023, 10:28 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,144
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

Quote:
Note that when you remove all content of that CC, it will display the placeholder text which may or may not suit your purposes. You can either edit the placeholder text or put a single space in the placeholder to avoid this problem
If you fill the content control with zero width space ChrW(8203) the control will completely disappear, but will still be present to be refilled with something else.
Code:
Sub Macro1
    FillCC "MyCCTitle", ChrW(8203), True

End Sub
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
        With oCC
            If .Title = strCCTitle Then
                .LockContents = False
                .Range.Text = strValue
                .LockContentControl = True
                .LockContents = bLock
                Exit For
            End If
        End With
    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