![]() |
#1
|
|||
|
|||
![]()
Hi
Anyone who could help in differentatiate between Relative line number and Absolute Linenumber. Seems a mistake at the when running the following code from VBA Express : Word - Get Line and Paragraph Number If one observes the Relative and Absolute line number which displays the same when macro is executed. If absolute line number is the Exact position of the actual line number of the document where the cursor is on current line position then why relative line number is same as absolute. Should not relative line number be like for eg. Line 2 of Paragraph 3. Ideally i would prefer to get Paragraph Number and Respective Line no of that Paragraph ir if iam on Paragrpah 3 then if the cursor is on line2 of Paragraph Then it should Display Paragraph 3 Absolute/Relative Line Number 2. Although Absolute/Relative Line Number 10 is displayed with following result with below code i get the following result Quote:
Quote:
Code:
Option Explicit Sub WhereAmI() MsgBox "Paragraph number: " & GetParNum(Selection.Range) & vbCrLf & _ "Absolute line number: " & GetAbsoluteLineNum(Selection.Range) & vbCrLf & _ "Relative line number: " & GetLineNum(Selection.Range) End Sub Function GetParNum(r As Range) As Integer Dim rParagraphs As Range Dim CurPos As Long r.Select CurPos = ActiveDocument.Bookmarks("\startOfSel").Start Set rParagraphs = ActiveDocument.Range(Start:=0, End:=CurPos) GetParNum = rParagraphs.Paragraphs.Count End Function Function GetLineNum(r As Range) As Integer 'relative to current page GetLineNum = r.Information(wdFirstCharacterLineNumber) End Function Function GetAbsoluteLineNum(r As Range) As Integer Dim i1 As Integer, i2 As Integer, Count As Integer, rTemp As Range r.Select Do i1 = Selection.Information(wdFirstCharacterLineNumber) Selection.GoTo what:=wdGoToLine, which:=wdGoToPrevious, Count:=1, Name:="" Count = Count + 1 i2 = Selection.Information(wdFirstCharacterLineNumber) Loop Until i1 = i2 r.Select GetAbsoluteLineNum = Count End Function |
|
![]() |
||||
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 |
![]() |
pmahesha | Word | 2 | 04-13-2015 12:16 PM |
![]() |
Cellendhyll | Word Tables | 3 | 07-10-2014 05:49 AM |
![]() |
peytontodd | Word | 2 | 12-11-2012 06:55 PM |