none
Is there a way to count the number of bullets per paragraph where the user places the cursor? RRS feed

  • Question

  • Hi All,

    Is there a way to count bullets per paragraph as and when / where the user places the cursor?

     private void Test_Para_Click(object sender, RibbonControlEventArgs e)
                {
                    object oMissing = System.Reflection.Missing.Value;
                    Word._Document oDoc;
                    oDoc = Globals.ThisAddIn.Application.ActiveDocument;
                    Word.Paragraph p;
                    Word.Range rParas;
                    p = oDoc.Application.Selection.Range.Paragraphs[1];
                    rParas = oDoc.Content;
                    rParas.End = p.Range.End;
                    int counter = 0;
                    int i=rParas.Paragraphs.Count;
                    MessageBox.Show("para num" + i);//gives every new line as a new paragraph number
                    try
                    {
                        counter = oDoc.Lists[i].ListParagraphs.Count;//does not give any value since every single line is taken as a new para
                        MessageBox.Show("bullet num" + counter);
                    }
                    catch
                    {

                        ;
                    }

    }


    Monday, December 1, 2014 5:20 AM

Answers

  • Hi Apoorva,

    Base on your code, I don’t know why you to get Lists base on paragraph’s count. Pleaes provide the detail information.

    According to your description, I don’t understand clearly about you said count bullects per paragraph. Please provide the detail information about your requirement.

    Do you want to count bullect of current cursor?

    If so, you could iterate the Lists of current document, then compare start, end range of current List with current section’s start, for example currentListStart<=sectionStart And currentListEnd>=sectionStart, then get count of current List item.

    A simple could of VBA that you could refer to:

    Dim i As Integer
    
    Dim li As Word.List
    
    Dim cursoStart As Integer
    
    cursoStart = Selection.Range.start
    
    i = ActiveDocument.Lists.Count
    
    For Each li In ActiveDocument.Lists
    
    If li.Range.start <= cursoStart And li.Range.End >= cursoStart Then
    
      MsgBox "List " & i & " has " & li.CountNumberedItems _
    
     & " items."
    
     Exit For
    
    End If
    
     MsgBox "List " & i & " has " & li.CountNumberedItems _
    
     & " items." & "paragraphs count" & li.ListParagraphs.Count
    
     i = i - 1
    
    Next li
    

    On the other hand, for the text warp to a new line, it is a paragraph.

    If I miss understand you, please provide more information of your requirement.

    Best Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, December 2, 2014 9:50 AM
    Moderator

All replies

  • Hi Apoorva,

    Base on your code, I don’t know why you to get Lists base on paragraph’s count. Pleaes provide the detail information.

    According to your description, I don’t understand clearly about you said count bullects per paragraph. Please provide the detail information about your requirement.

    Do you want to count bullect of current cursor?

    If so, you could iterate the Lists of current document, then compare start, end range of current List with current section’s start, for example currentListStart<=sectionStart And currentListEnd>=sectionStart, then get count of current List item.

    A simple could of VBA that you could refer to:

    Dim i As Integer
    
    Dim li As Word.List
    
    Dim cursoStart As Integer
    
    cursoStart = Selection.Range.start
    
    i = ActiveDocument.Lists.Count
    
    For Each li In ActiveDocument.Lists
    
    If li.Range.start <= cursoStart And li.Range.End >= cursoStart Then
    
      MsgBox "List " & i & " has " & li.CountNumberedItems _
    
     & " items."
    
     Exit For
    
    End If
    
     MsgBox "List " & i & " has " & li.CountNumberedItems _
    
     & " items." & "paragraphs count" & li.ListParagraphs.Count
    
     i = i - 1
    
    Next li
    

    On the other hand, for the text warp to a new line, it is a paragraph.

    If I miss understand you, please provide more information of your requirement.

    Best Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, December 2, 2014 9:50 AM
    Moderator
  • Thanks a lot Starain , this is what i was looking for, I forgot all about the foreach loop :) 
    Wednesday, December 3, 2014 6:09 AM