0
votes

I create a table of figures programmatically in a Word document.

Well, the ToF style is centered and I would like it to be left indent. To do so (set paragraph indention) I have to get the paragraph where the ToF is located.

This is the way rto access the ToF:

wordApp.ActiveDocument.TablesOfFigures[1]

Any ideas?

2
you want to choose a answer? - Jean-Pierre Oosthuizen

2 Answers

1
votes

Try the code below. Assuming that TablesOfFigures[1] is exists (otherwise we will get buffer overflow).

// Check in which paragraph TablesOfFigures[1] is found
for (int i=1; i <= wordApp.ActiveDocument.Paragraphs.Count; i++)
{
    if (IsInRange(wordApp.ActiveDocument.TablesOfFigures[1].Range, wordApp.ActiveDocument.Paragraphs[i].Range))
    {
        MessageBox.Show("ToF is in paragraph " + i);
    }

}

// Returns true if 'target' is contained in 'source'
private bool IsInRange(Range target, Range source)
{
    return target.Start >= source.Start && target.End <= source.End;
}
1
votes

Provided that you only have one Table of Figures, you can try this:

 With wordApp.ActiveDocument.TablesOfFigures(1).Range

     'Setting the indent
     .ParagraphFormat.LeftIndent = CentimetersToPoints(1)

 End With

I have tested it just using Word and it Selects the Table of Figures and then Indents it by 1cm