View Single Post
 
Old 02-26-2024, 03:35 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

You've got a few problems with your code. Here is the basics
You could have more than one content control with the same title so you would need to be specific about which one you are talking about. eg the first one might be
Set aCC = ActiveDocument.SelectContentControlsByTitle("Name" )(1)

However, if you assume that there is at least one CC with that name in the document and it doesn't exist, then you have to handle an error. To avoid that, I've set up a loop that handles none, one or more instances without crashing

Code:
Sub CheckContentControl()
  Dim aCC As ContentControl, bEmpty As Boolean
  For Each aCC In ActiveDocument.SelectContentControlsByTitle("Name")
    bEmpty = aCC.ShowingPlaceholderText
    If bEmpty Then
      MsgBox "The Content Control is Empty"
    Else
      MsgBox "The Content Control has content"
    End If
  Next
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote