Solved

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

Posted on 2009-04-05
3
8,823 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
ID: 24076895
Hi
You can use RemoveNumbers method:

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

oNumberType is wdNumberParagraph

Regards
  Danso

0
 
LVL 23

Expert Comment

by:irudyk
ID: 24076957
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
ID: 31566854
Thank you for your solution - it was very much appreciated and resolved my problem!
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
HttpPostedFile 1 26
.NET 2008 VB and C# 6 28
What Does This C# Code Block Do? 5 30
MailAddress in vb 4 15
Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…

773 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