none
The Word API (Range.End) doesn't correctly determine the end of the paragraph RRS feed

  • Question

  • I've created a plugin for MSWord. This is a plugin which has a keyboard hook. When I am typing some text my plugin gets the end of the range (Range.End) at the current paragraph. This value is always incorrect (bigger then the actual one).
    When I stop typing and get this value by timer the value still isn't correct.

    e.g.

    This a test sentence[cursor position is here]
    ......
    some text
    ......

    Aplication.Selection.Range.Paragraphs[1].End result is wrong. I think it should be 21

    But if I move the cursor in the sentence to the left and to the right (left arrow, right arrow), End will have the correct result.


    • Edited by A.K.Net Friday, September 30, 2011 7:11 AM
    Friday, September 30, 2011 7:06 AM

Answers

  • Hi A.K.Net,

    Thanks for your post.

    Based on my understanding, you want to determine the end of the paragraph. If so, you could calculate the length of the paragraph, please try below code, which returns the result 21.

    The first paragraph in test.docx is:

    This a test sentence[cursor position is here]

    Sub test()
    Dim wordapp As Word.Application
    Set wordapp = New Word.Application
    Dim worddoc As Word.Document
    Set worddoc = wordapp.Documents.Open("D:\test.docx")
    Dim i As Integer
    i = Len(worddoc.Paragraphs(1).Range)
    MsgBox i
    End Sub
    

    If you have any concerns, please feel free to follow up.

    Have a nice day.

    Best regards


    Liliane Teng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Liliane Teng Monday, October 10, 2011 9:55 AM
    Thursday, October 6, 2011 5:12 AM

All replies

  • I'm confused. Are you talking about ranges or selections?  Yes a selection has a range but it can be very different than an operating Range command might be addressing.

    Can you show actual code and where you are getting abnormal results?  And what is the version of Word you are working with?


    Kind Regards, Rich ... http://greatcirclelearning.com
    Saturday, October 1, 2011 3:41 AM
  • He's talking about Range. And he talking about what he not have actual value of property End of Range then he get it while key board hook handled
    Saturday, October 1, 2011 12:18 PM
  • When you think it should be 21, what value do you actually get?
     

    Enjoy,
    Tony
    www.WordArticles.com
    Sunday, October 2, 2011 6:43 PM
  • Hi A.K.Net,

    Thanks for your post.

    Based on my understanding, you want to determine the end of the paragraph. If so, you could calculate the length of the paragraph, please try below code, which returns the result 21.

    The first paragraph in test.docx is:

    This a test sentence[cursor position is here]

    Sub test()
    Dim wordapp As Word.Application
    Set wordapp = New Word.Application
    Dim worddoc As Word.Document
    Set worddoc = wordapp.Documents.Open("D:\test.docx")
    Dim i As Integer
    i = Len(worddoc.Paragraphs(1).Range)
    MsgBox i
    End Sub
    

    If you have any concerns, please feel free to follow up.

    Have a nice day.

    Best regards


    Liliane Teng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Liliane Teng Monday, October 10, 2011 9:55 AM
    Thursday, October 6, 2011 5:12 AM