• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to get current paragraph number

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic