I want to place a contentcontrol within ( an existing) bookmark, but only if there is currently no contentcontrol in the bookmark which already contains text. there might be normal text though in the bookmark which can we overwritten.
This is what I have so far:
Dim objcc As ContentControl
Dim abmr As Range
'This adds the contentcontrol to the bookmark. I want to use the tag to identify the contentcontrol later, and the placeholder text to check if it is empty or not:
Set objCC = ActiveDocument.Bookmarks("bk_SectionXII").Range.ContentControls.Add_ wdContentControlRichText)
objCC.Range.text = ""
objCC.SetPlaceholderText text:="Copy Quality Agreement here"
objCC.Tag = "CC_QualityAgreement"
objCC.Range.Font.Color = wdColorRed
' this sets the bookmark back around the control, so that the macro can used repeatedly:
Set abmr = ActiveDocument.Bookmarks("bk_SectionXII").Range.Paragraphs(1).Range
abmr.MoveEnd Unit:=wdParagraph, Count:=1
abmr.MoveEnd Unit:=wdCharacter, Count:=-1
ActiveDocument.Bookmarks.Add Name:="bk_SectionXII", Range:=abmr
Now, what I need is something which checks whether the contentcontrol with the tag "CC_QualityAgreement" exists, and whether it is empty or not. Empty is considered if the placeholder text "Copy Quality Agreement here" appears. Everything else is considered not empty.
If contentcontrol is there and if empty: do nothing
if contentcontrol is there but with (other than the placeholder) text: Ask if it should replaced with empty control; if yes, replace, if no, do nothing
If bookmark contains other text (anything else), overwrite and place contentcontrol within bookmark.
I tried with for each contentcontrol (objcc) in ActiveDocument.ContentControls
If objcc.tag = "CC_QualityAgreement" then
etc, but it don't lead me knowhere.
Help is highly appreciated