Questions tagged [word-contentcontrol]

For questions involving working with Microsoft Word ContentControl objects in the Word object model, VSTO extended objects, Word Open XML file format or the Office JS APIs.

Word content controls were introduced in Word 2007 as an alternative / replacement for bookmarks and form fields. The original content control types:

  • Plain text
  • Rich text
  • Date selector
  • Building Block Gallery
  • Picture box
  • Drop-down list
  • ComboBox
  • Group

Word 2010 added the content control type

  • Checkbox

Word 2013 added the content control type

  • Repeating section

There are a number of events available for content controls. These are at the document-level:

  • ContentControlAfterAdd
  • ContentControlBeforeContentUpdate
  • ContentControlBeforeDelete
  • ContentControlBeforeStoreUpdate
  • ContentControlOnEnter
  • ContentControlOnExit

Content controls can be mapped to nodes in a Custom XML Part within the document. The content is then synced between node and content control (they have the same content).

In contrast to form fields or bookmarks, multiple Word content controls can have the same name (Title). They also have the Tag and Id properties. Only the Id, which is unique and assigned by the Word application to the content control, can be used as an index value to identify a specific content control.

To pick up content controls by their Title or Tag the SelectContentControlByTitle / SelectContentControlByTag methods must be used. These return a Collection. Title and Tag are case-sensitive.

Form field protection also applies to content controls: when the document is protected as a form content controls can be available for editing.

150 questions
15
votes
3 answers

Replacing Content Controls in OpenXML

I need something as a placeholder. I at first looked to Content Control as a solution but I'm having some problems with it. I then looked into adding CustomXML to the .docx but turned away from that because of the i4i lawsuit. Then I decided I would…
Ingó Vals
  • 4,788
  • 14
  • 65
  • 113
4
votes
3 answers

How to get the list of all content controls in the document?

I am using interop and I want to get the list of all content controls contained in word document (in the body, shapes, header, footer..). Is this the correct and the best way to do this : public static List
DevTun
  • 865
  • 1
  • 8
  • 24
3
votes
0 answers

Broken content control in Word document

In my office js app for Word, sometimes a content control looses connection, so I cannot see the content control any longer, and then the document is broken for inserting new content controls of that type. I am not able to delete the broken content…
3
votes
1 answer

MS Word JavaScript API - event handler for Content Controls

Is there a way to fire a function when clicking on a contentControl in Office-js? I am writing an add-on for MS Word, and I have inserted content controls, that will be associated with a list in my add-in. I need to fire a function when clicking on…
3
votes
1 answer

SetPlaceholderText in MS Word Form from Excel

I'm writing an Excel VBA macro to translate an MS Word Form into various languages. The original English phrases are listed in column A, and the corresponding translations are listed in cols B, C, etc. No problem substituting translation for…
P E
  • 165
  • 11
3
votes
2 answers

OpenXML: Creating reusable Content Controls with binding

I need to attach specific XML to a word document so the elements will show up in the right places. This I can do with OpenXML SDK. The thing is I want too be able to define the Content Controls already bounded in some sort of template so other…
Ingó Vals
  • 4,788
  • 14
  • 65
  • 113
3
votes
1 answer

Replacing Text of Content Controls in OpenXML

I have a word file that have multy Rich Text Content Control I want to change text of it. I Use this code . using (WordprocessingDocument theDoc = WordprocessingDocument.Open(docName, true)) { MainDocumentPart mainPart =…
ar.gorgin
  • 4,765
  • 12
  • 61
  • 100
2
votes
0 answers

Is there a way to detect changes to the content control in word in office js?

I've got a script that finds all matching bits of text and puts them in a content control. I noticed there was a functionality to remove the content control if the text was edited ContentControl.removeWhenEdited = true. Is there a way to run this…
2
votes
0 answers

How to change the content control placeholder text font style w.r.p to document font style

I am developing a word add-in using VS c#. As a requirement I need to add a content control to document on a ribbon button click. I am successful in adding content control with placeholder text. But the font style of the placeholder text is always…
Anup
  • 29
  • 1
2
votes
2 answers

document.contentControls not returning all ContentControls in the document

I have a document with three ContentControl objects that looks like this: Here is the .docx file in its entirety - but essentially the markup of the document body looks like this:
Leo
  • 5,013
  • 1
  • 28
  • 65
2
votes
0 answers

Not able to retrieve content control from word table in office 365 word online

We have a product which supports on O365 windows and mac using office js. Now on the same product, we are going to support on O365 word online. During our work, we have found one discrepancy in O365 windows and word online. We have a document that…
2
votes
0 answers

Inserting Content Control on empty spaces

I'm working on a MS Word Add-in project and basically there is one use case wherein I need to insert content controls on selected content on the document. I was able to do it easily however there is one issue where in if the selected content are…
mrDev87
  • 21
  • 5
2
votes
1 answer

Get Index of Specific Content Control based on ID or Title

I would like to retrieve the word content control's index via VBA given a specific title without having to loop through all content controls looking for the title. I know the title of the content control that I would like to select therefore I can…
Ian
  • 187
  • 1
  • 10
2
votes
1 answer

Office.js get range adjacent to a content control

I have the following scenario Word: text document with some content controls (also text) content controls are always adjacent to normal text (without a space between the text and the content control) content controls have the same style as the…
dnmh
  • 2,045
  • 2
  • 34
  • 49
2
votes
1 answer

Word Macro to Deselect a content control after macro

My current project is making a list for a coworker and since I like to over-complicate everything, I'm running macros for him to check off as he completes work. The description of work will change from a header style to normal when he's completed…
Reece
  • 79
  • 2
  • 11
1
2 3
9 10