Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #8  
Old 01-22-2021, 08:58 AM
gmaxey gmaxey is offline How to get respective/relative Line Number of a Paragraph ? Windows 10 How to get respective/relative Line Number of a Paragraph ? Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Sam,


"Every line in word is a paragraph" That is not true. A paragraph can have one line or hundreds. What is true is every press of the Enter key creates a new paragraph. If you press it twice and then start typing then you created two (one for space and one for your text).


As Andrew said, checking every paragraph to see if it is empty would just add to the time is take to process and return the user location.

That is one of the drawbacks of the GetLocation method. It is evaluating every page, every rectangle, every line up to the the users selection point. That is a laborious process. Nothing for a short letter or two or three page document but a big drag in a big document. I have a document that is 1510 pages long. I have a very robust PC and it still look close to a minute to report the cursor look on page 1500.


However, if you wanted to exclude empty paragraphs, and empty text rectangle in the document structure has a range length of 1. So you could modify to:


Note: This code has not be tested with documents containing tables or other graphical elements.


Code:
Sub GetLocation()
Dim oPage As Page
Dim oRect As Rectangle
Dim oLine As Line
Dim lngPage As Long, lngRect As Long, lngLine As Long
Dim lngParCount As Long, lngLineCount As Long, lngPLCount As Long
Dim bResolved As Boolean
  bResolved = False
  
  For lngPage = 1 To ActiveDocument.ActiveWindow.Panes(1).Pages.Count
    Set oPage = ActiveDocument.ActiveWindow.Panes(1).Pages(lngPage)
    For lngRect = 1 To oPage.Rectangles.Count
      Set oRect = oPage.Rectangles(lngRect)
      On Error GoTo Err_Handler
      If oRect.Range.StoryType = wdMainTextStory Then
        If oRect.RectangleType = wdTextRectangle Then
          If Len(oRect.Range) > 1 Then 'An empty TextRectangle as a range lenght = 1
            lngParCount = lngParCount + 1
            If Selection.InRange(oRect.Range) Then
              For lngLine = 1 To oRect.Lines.Count
                Set oLine = oRect.Lines(lngLine)
                lngPLCount = lngPLCount + 1
                If Selection.InRange(oLine.Range) Then
                  lngLineCount = lngLineCount + lngPLCount
                  bResolved = True
                  Exit For
                End If
              Next lngLine
            Else
              lngLineCount = lngLineCount + oRect.Lines.Count
            End If
          End If
          If bResolved Then Exit For
        End If
      End If
NextRect:
    Next lngRect
      If bResolved Then Exit For
  Next lngPage
  MsgBox "The cursor is in Dococument paragraph number: " & lngParCount & vbCr _
       & "Document line number: " & lngLineCount & vbCr _
       & "Paragraph line number: " & lngPLCount
lbl_Exit:
  Exit Sub
Err_Handler:
  Resume NextRect
End Sub

"So any type of indication thru VBA or any VBA syntax to know what style has been used for inter-paragraph and what spacing has been incorported.
Rather than Selecting document/Paragraph and checking for Space Size after each paragraph"


You could do a find and replace looking for ^13^13. Any found would indicate the user has used paragraphs for spacing.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
syntax for inserting blank line before inserting table and after a line or paragraph SamDsouza Word VBA 8 08-04-2019 11:10 PM
Data validation,force cell to be filed with number if respective cell is not empty nicholes Excel Programming 0 08-01-2015 09:08 AM
How to get respective/relative Line Number of a Paragraph ? Hanging relative to the number pmahesha Word 2 04-13-2015 12:16 PM
How to get respective/relative Line Number of a Paragraph ? How to create a table with a number of line depending a number entered by user Cellendhyll Word Tables 3 07-10-2014 05:49 AM
How to get respective/relative Line Number of a Paragraph ? How set up a 'paragraph number'? peytontodd Word 2 12-11-2012 06:55 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:20 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft