Excel Hints

Results 1 to 2 of 2

Thread: Content Control and VBA

  1. #1

    Question Content Control and VBA

    Does anyone know how to reference a Rich Text Content Control field using VBA. I am trying to write some VBA code that will look at the value in a Content Control field and run a script based on the field. Only problem is I cant figure out the reference the field using VBA.

  2. #2
    VB:
    Sub ScratchMacro() 
         'CCs can be referenced in the following ways:
         '  1. By their position (Index number) in the document.
         '  2. By Title and item number
         '  3. By Tag ane item number
         '  4. By a unique ID defined when the CC is created.
        MsgBox ActiveDocument.ContentControls(1).Range.Text 
         'Since Title and Tag are not unique you need to use Item as well.
        MsgBox ActiveDocument.SelectContentControlsByTitle("Test").Item(1).Range.Text 
        MsgBox ActiveDocument.SelectContentControlsByTag("Test").Item(1).Range.Text 
         'Select the CC and get its ID
        Debug.Print Selection.Range.ContentControls(1).ID 
         'Reference by ID.
        MsgBox ActiveDocument.ContentControls("420146660").Range.Text 
    End Sub 
    
    
    Formatting tags added by mark007

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •