Domanda

I'm trying to edit a .docx header through Word Automation. If the Content Controls are placed in the body of the text there is no problem, but if the content controls are in the header or footer I'm not able to target them. Is there any way of targetting Content Controls in the header or footer (using Visual Studio 2008 Express)?

È stato utile?

Soluzione 2

Using Word Automation one way of targetting ContentControls in the header can be:

        Dim ContControlCollec As Word.ContentControls
    ContControlCollec = WordDoc.Doc.Sections(1).Headers(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage).Range.ContentControls

        ContControlCollec.Item(1).Range.Text = Text1
        ContControlCollec.Item(2).Range.Text = Text2

Altri suggerimenti

Word has what are called Stories in the StoryRange collection - most routines run on the main body of the document itself of the wdMainTextStory type of WdStoryType, unless you specifically change stories.

Here's a way to get to your controls in the header:

Dim ad as Document
Set ad = ActiveDocument
For Each objCC In ad.Sections(1).Headers(wdHeaderFooterPrimary).Range.ContentControls 
    ''# Do your thing 
Next 
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top