add group content control to text in shape or to shape

User avatar
Charles Kenyon
4StarLounger
Posts: 596
Joined: 10 Jan 2016, 15:56
Location: Madison, Wisconsin

add group content control to text in shape or to shape

Post by Charles Kenyon »

I am trying to add a shape with text to a document and then add a Group Content Control to the text.
I've tried the following and get an error message:

Code: Select all

Activedocument.Shapes(1).Range.contentcontols.add(wdcontentcontrolgroup)
The error is a compile error: Argument not optional

I get the same error message with:

Code: Select all

activedocument.Shapes.Range.TextFrame.ContainingRange.ContentControls.Add (wdContentControlGroup)
I can do this manually in the UI by selecting the text and applying a group control. It is a matter of specifying the text in the shape.

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: add group content control to text in shape or to shape

Post by HansV »

Does this work for you?

Code: Select all

    ActiveDocument.Shapes(1).TextFrame.TextRange.Select
    ActiveDocument.ContentControls.Add wdContentControlGroup, Selection
Selecting stuff in a macro is not ideal, but it was the only way I could make it work...
Best wishes,
Hans

User avatar
Charles Kenyon
4StarLounger
Posts: 596
Joined: 10 Jan 2016, 15:56
Location: Madison, Wisconsin

Re: add group content control to text in shape or to shape

Post by Charles Kenyon »

:clapping: Thank you. It works a charm.