title: Inserting a Plain Text Content Control with a Macro
body: <p>I am trying to automate the generation of a pre-existing and original .docx form using a macro and need to insert plain text Content Controls into the form in various locations via the macro. On the original .docx form, the Content Control fields are 8 underlined spaces and are surrounded by parentheses. In the original form, when I click on the Content Controls, I only need to click once, and when I click on it and input information, the underlined spaces disappear and I'm left with only the text that I've entered and the parentheses. How do you make a Content Control that has these properties with VBA? In my macro-generated document, I have to click first in the Content Control on the underlined spaces and then on the 3 dots to the left in order to enter the data. However, when I do this in the macro generated document, the underlines stay. If I click once on the Content Control in the macro generated document, the input is added to the spaces instead of replacing them. Also, how do you underline the spaces in the Content Control such that the underline is present before the Content Control is clicked on but disappears when the text is entered? The parentheses should not be underlined at any point.</p>
  <p>I tried the below code. I spent about 2 hours googling stuff to try to find a solution and was unsuccessful. I also tried doing it with objects, but I lost that code and can't seem to find it. That object code that I found didn't work either.</p>
  <pre><code>Private Sub POAContentControl()
      
      With Selection
          .TypeText Text:=&quot;(&quot;
          .Range.ContentControls.Add (wdContentControlText)
          .TypeText Text:=&quot;        &quot;
          .Font.UnderlineColor = wdColorAutomatic
          .Font.Underline = wdUnderlineSingle
          .EndKey unit:=wdLine 'Exits the Content Control
          .Font.Underline = wdUnderlineNone
          .TypeText Text:=&quot;)&quot;
      End With
      
  End Sub
  </code></pre>