Solved

How do I insert and remove bullet points using C# with Word

Posted on 2009-04-05
3
8,683 Views
Last Modified: 2012-05-06
Hi,
I am using C# to automatically populate text in a Word Document. I need a certain paragraph to have bullet points but the next paragraph revert to normal text. I can insert the bullet points but cannot remove them. I am using the following code:


 Object oTrue = true;
 Object oFalse = false;
 Object oTemplatePath = @"C:\SampleTemplate.dotx";
Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document oDoc = new Microsoft.Office.Interop.Word.Document();
Microsoft.Office.Interop.Word.Paragraph oPara1;

oWord.Visible = true;
oDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);
oPara1 = oDoc.Content.Paragraphs.Add(ref oMissing);

oPara1.Range.ParagraphFormat.LeftIndent = -1;
oPara1.Range.ListFormat.ApplyBulletDefault(ref oMissing);
oPara1.Range.Text = "Sample Text that has a preceding bullet point";

oPara1.Range.InsertParagraphAfter();

//Here I need to remove the bullet point on the next paragraph


Any help would be greatly appreciated.

Thanks
David
0
Comment
Question by:dvscie
3 Comments
 
LVL 7

Accepted Solution

by:
DanSo1 earned 250 total points
Comment Utility
Hi
You can use RemoveNumbers method:

oPara1.Range.ListFormat.RemoveNumbers(ref oNumberType);

oNumberType is wdNumberParagraph

Regards
  Danso

0
 
LVL 23

Expert Comment

by:irudyk
Comment Utility
Try the following:
oPara1.Range.InsertParagraphAfter();

//Here I need to remove the bullet point on the next paragraph

oPara1.Range.ListFormat.RemoveNumbers();
0
 

Author Closing Comment

by:dvscie
Comment Utility
Thank you for your solution - it was very much appreciated and resolved my problem!
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now