none
How to insert a paragraph within bullets. RRS feed

  • Question

  • I am trying to automate the creation of a standard document.  To create this document users select a list of items from a user form and insert the selected items in bullet format into the document template.  Normally, this process is made manually and every user create his or her own version of the document.  The automation of the procedure is to make a true standard document and eliminate personalized versions.  I have created most of the process, except that I am unable to find a way of inserting paragraphs within the bullets.  The way I automated the process is by creating a word template with bookmarked lines, after which the bullet items are inserted.  I have a routine that takes a bookmark and a list of bulleted items then it finds the bookmark on the document and inserts the bullets, please see attached code.  Also please see the attached image of the document I am trying to create (a sample).  In this document Title One and Title Two are bookmarked on the template, the InsertBullets routine finds them an populates the bullets.  The two paragraphs in bold, the warning and attention, are the paragraphs I need to insert within the bullets but I have not found a way of doing it.  If anyone could provide some help or samples code I will really appreciate it.

    private void InsertBullets(string Bookmark, List<string> BulletList)
    {
    	Word.Document Doc = Application.ActiveDocument;
    
    	if (Doc.Bookmarks.Exists(Bookmark) == true)
    	{
    		Word.Range rg = Doc.GoTo(Word.WdGoToItem.wdGoToBookmark, Name: Bookmark);
    
    		rg.Select();
    
    		rg.InsertParagraphAfter();
    
    		Application.Selection.Move(Word.WdUnits.wdLine, 1);
    
    		rg = Application.Selection.Range;
    
    		rg.Select();
    
    		Application.Selection.Font.Size = 12;
    
    		Application.Selection.Font.Bold = (int)Word.WdConstants.wdToggle;
    
    		Word.ListGallery lstgall = Application.ListGalleries[Word.WdListGalleryType.wdNumberGallery];
    
    		object o = 5;
    
    		Word.ListTemplate lstTpl = lstgall.ListTemplates.get_Item(ref o);
    
    		rg.ListFormat.ApplyListTemplate(lstTpl);
    
    		System.Globalization.TextInfo textInfo = new System.Globalization.CultureInfo("en-US", false).TextInfo;
    
    		for (int i = 0; i < BulletList.Count; i++)
    		{
    			if (i < BulletList.Count - 1)
    			{
    			  rg.InsertAfter(string.Format("{0}\r", BulletList[i], i.ToString()));                       
    			}
    			else
    			{
    				rg.InsertAfter(string.Format("{0}", BulletList[i], i.ToString()));
    			}
    		}
    	}
    }

    Friday, March 29, 2019 5:34 PM