Reputation: 2661
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?
Upvotes: 0
Views: 545
Reputation: 2693
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
Upvotes: 1
Reputation: 2746
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;
}
Upvotes: 1