none
Line Count area of Document RRS feed

  • Question

  • I have been working with Word via VSTO.  My application assists engineers commenting against documents and needs to supply a line count.  The Word Line Count is not an accurate number according to the Interop Object model (i.e., the line count from the object model is not the same as that indicated by the line count function provided by Word).  I use the line count from the object model extensively in the application.   Normally I wouldn't care, but I need consistency in the numbers. 

    My question is, how can I gain access to the physical space on the page that the Word Line Count function uses and put my own generated numbers there?  Is it possible to specify an exact location when adding text to a page?

    Monday, October 2, 2017 2:15 PM

All replies

  • Hello,

    Do you mean the Word Count in Review tab? It it impossible to change the information in that message box. Why do you want to replace it with your own number? Does the built-in count would get wrong result?

    What code do you use to get the Word Line Count in VSTO add-in? 

    ActiveDocument.BuiltInDocumentProperties(wdPropertyLines) would return correct line counts and it is the same as the information in Word Count message box. 

    Regards,

    Celeste



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, October 3, 2017 4:23 AM
    Moderator
  • Thanks for replying Celeste.  The Interop object model most certainly does NOT count the same as the Layout -> Line Numbers -> Continuous.  The latter ignores tables and footnotes, the former does not.  In tests I have run on a modest sized engineering document, the line count is off by over 200 lines after 60 pages.

    I am not trying to change the Word count - I am trying to replace the numbers placed on the left margin by the faulty Line Count function with another.  I want to know how the Line Count function is able to place text to the left of the left margin.

    Any help is appreciated.

    Tuesday, October 3, 2017 11:29 AM
  • Hello,

    Thanks for the information. The line numbering is a product feature, i dont think the feature is achieved using Interop library. Word Object Model does not provide any properties or method to return the line numbers. It also does not provide any method to add text on left margins. To work around, you could negative Indent of the paragraph or add text box at each line and set the line number.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, October 4, 2017 8:38 AM
    Moderator
  • Thank you for replying Celeste.  I realize the line numbering is not part of the object model.  I was just hoping to replace it with my own version and wondered how that feature added numbers - I'm curious how it works.

    I'll give the text box a try and see if it's workable.  I'll report back my progress here.

    Wednesday, October 4, 2017 2:21 PM
  • Hi FlyinBlind,

    >> The Word Line Count is not an accurate number according to the Interop Object model (i.e., the line count from the object model is not the same as that indicated by the line count function provided by Word)

    In my option, it is hard to say which is right since they are based on different rules to count lines.

    For Layout -> Line Numbers -> Continuous, it did not count table.

    For Word Count feature which is VBA code like “ActiveDocument.BuiltInDocumentProperties(wdPropertyLines)”, its value equals line count plus (table row)*(table column).

    >> Normally I wouldn't care, but I need consistency in the numbers.

    None of them you could change. Both are features provided by Word application. We could not change them.

    >> My application assists engineers commenting against documents and needs to supply a line count

    What do you mean by this? If you need to provide line count on each line, I could not custom the value, and I would suggest you keep using Line Count, and share the end user the difference between line count and word count.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, October 9, 2017 8:11 AM
  • Hi Edward,  Thank you for replying.  I have, apparently, been using term "Line Count" incorrectly as what I mean is "Line Numbering" of each sentence in the document.

    On very large documents, the number that is placed on the page and what is returned through the Interop Object Model diverge to such an extent that they are not of value to reviewers (which I believe is the target of the Line Numbering function). 

    Is there somewhere that describes what is and what is not counted in Line Numbering?  If so, I'll adjust my code.  At this point, I'm just guessing.

    Thanks again for replying.

    Tuesday, October 10, 2017 5:33 PM
  • Hi FlyinBlind,

    >> Is there somewhere that describes what is and what is not counted in Line Numbering?

    I am afraid there is no such document related with this information.

    But, I think you could comparing the result between Line Count and Line Numbering to check which we should exclude like table object.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, October 11, 2017 3:24 AM