tags:

views:

272

answers:

2

Is there a way to find all ContentControls of a WordDocument (including ContentControls in Headers, Footers, TextBoxes ...) using VSTO?

Microsoft.Office.Tools.Word.Document.ContentContols returns only the ContentControls of the Main-Document, not the one inside the Headers/Footer.

A: 

Try this:

foreach (Word.ContentControl contentcontrol in this.Application.ActiveDocument.ContentControls)
{
    //Some action on all contentcontrol objects
}

If that doesn't work try to iterate on all ranges (for contentcontrols) in a document's StoryRanges

Mike Regan
A: 

I'm dealing with the same problem, but driving Word from MATLAB. This page by a Word MVP solved the problem for me:

http://www.word.mvps.org/FAQs/MacrosVBA/FindReplaceAllWithVBA.htm

Essentially, you have to:

  1. Loop over all Document.StoryRanges to get the first range of each story type.
  2. Within each range, do your job on range.ContentControls.
  3. range = range.NextStoryRange.
  4. Repeat 2-4 until range is empty.
Arthur Ward