Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get current paragraph number

 
Tamil Selvi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,

I am using C#.net with the component of Ms-Word 2003. I am trying to find the Bold word in paragraph-wise (each para have more that one bold words) and get the current paragraph number. So i used below code for searching which has not worked. It do a search on entire word document instead of a specified paragraph.


My Coding Lines:
using msWord = Microsoft.Office.Interop.Word; //Included Ms-Word Namespace Microsoft Office 11.0 Object Library
int paraCnt = 0;
msWord.Application myWrd; //Create an instance for application and document.
msWord.Document myDoc;
object missing = Missing.Value;
object objFile = @"D:\Test\File.doc";

//Open an existing document
msWord._Document myDoc = myWrd.Documents.Open(ref objFile, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
for (int i = 1 ; i <= myDoc.Paragraphs.Count; i ++)
{
Microsoft.Office.Interop.Word.Range myRange = myDoc.Paragraphs[i].Range;
myRange.Select();
object beg = Microsoft.Office.Interop.Word.WdUnits.wdParagraph;
object end = Microsoft.Office.Interop.Word.WdMovementType.wdExtend;
object objTrue = true;
object objFalse = false;
object objWrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindStop;
object objReplace = msWord.WdReplace.wdReplaceNone;
object objFindText = "";
paraCnt += 1; //Incremented when the next paragaph starts
myRange.Find.Format = true;
myRange.Find.Font.Bold = 1;
myRange.Find.Text = "";

myRange.Find.Execute(ref objFindText, ref objFalse, ref objFalse, ref objFalse, ref objFalse, ref objFalse, ref objTrue, ref objWrap, ref objTrue, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
while (myRange.Find.Found)
{
MessageBox.Show(myWrd.Selection.Text); //Getting the selected text
MessageBox.Show(paraCnt.ToString()); //Here trying to get a current paragraph number
}
}
myDoc.Close(ref missing, ref missing, ref missing);

Please help me

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic