Hi All,
I have a ribbon button which inserts numbered bullets in my doc like so:
private void button4_Click_1(object sender, RibbonControlEventArgs e)
{
Word._Document oDoc;
oDoc = Globals.ThisAddIn.Application.ActiveDocument;
object oStart = oDoc.Application.Selection.Range.Start;
object oEnd = oDoc.Application.Selection.Range.End;
Word.ListGallery listGallery = Globals.ThisAddIn.Application.ActiveDocument.Application.ListGalleries[Word.WdListGalleryType.wdNumberGallery];
Word.ListFormat listFormat = null;
Word.Range rangeInitial = Globals.ThisAddIn.Application.Selection.Range;
Word.Range range = rangeInitial.Duplicate;
range.Start = range.End;
Word.Paragraph oPara;
oPara = oDoc.Content.Paragraphs.Add(range);
listFormat = oPara.Range.ListFormat;
this.ApplyListTemplate1(listGallery, listFormat, 1);
range.ListFormat.ListLevelNumber = 1;
}
and I have another button which applies levelled numbered bullets like 1.1 ,1.2 etc like this
private void button5_Click(object sender, RibbonControlEventArgs e)
{
Word._Document oDoc;
oDoc = Globals.ThisAddIn.Application.ActiveDocument;
object oStart = oDoc.Application.Selection.Range.Start;
object oEnd = oDoc.Application.Selection.Range.End;
Word.ListGallery listGallery = Globals.ThisAddIn.Application.ActiveDocument.Application.ListGalleries[Word.WdListGalleryType.wdOutlineNumberGallery];
Word.Range rangeInitial = Globals.ThisAddIn.Application.Selection.Range;
Word.Range range = rangeInitial.Duplicate;
range.Start = range.End;
Word.Paragraph oPara;
Word.ListFormat listFormat = null;
oPara = oDoc.Content.Paragraphs.Add(range);
listFormat = oPara.Range.ListFormat;
this.ApplyListTemplate1(listGallery, listFormat, 2);
oPara.Range.ListFormat.ListLevelNumber = 2;
}
Here is my apply list template:
private void ApplyListTemplate1(Word.ListGallery listGallery, Word.ListFormat listFormat, int level = 2)
{
listFormat.ApplyListTemplateWithLevel(
listGallery.ListTemplates[level],
ContinuePreviousList: true,
ApplyTo: Word.WdListApplyTo.wdListApplyToSelection,
DefaultListBehavior: Word.WdDefaultListBehavior.wdWord10ListBehavior,
ApplyLevel: level);
}