I am trying to highlight a content control in word 2007 header programmatically. I manage to do this in the main document, but the code can't find the content controls placed in the header.
My code looks like this
internal
{
Word.
}
Hi,
If your content control is placed in Header part, how can you search in main document?
Seach in header part part of your document.
Sheela
I realize that I loop through content controls in the main document and that I need to do the same for the header, but I just can't figure out how to get hold of the content controls in the header.
Can you help?
Are you using VSTO for this?
If so, please check this line
Globals.ThisAddIn.Application.ActiveDocument
See what other menthods are available to get hold of header part.
If this does not help, post this issue in VSTO/Word 2007 specific forum.
in C#
private IEnumerable<ContentControl> GetContentControls()
var document = Globals.ThisDocument.InnerObject;
var result = new List<ContentControl>();
if (document != null)
Range rangeStory;
foreach (Range range in document.StoryRanges)
rangeStory = range;
do
try
foreach (ContentControl contentControl in rangeStory.ContentControls)
result.Add(contentControl);
catch (COMException) { }
rangeStory = rangeStory.NextStoryRange;
while (rangeStory != null);
return result;
return null;