Information(wdFirstCharacterLineNumber) doesn't give correct results

T

Terry Hornsby

I have some code which is supposed to add a string page & line No to the
start of each paragraph. During runtime if I hover the cursor over the
..information portion of the endpagenumber statement it returns a number one
less than if I hover it over the bracketed portion of the statement. The
code returns the first number. If this isn't bizarre enough, if I do the
same with the firstcharacter statement the first part returns a value of -1
& the bracketed bit returns a value of 10. The code returns -1, but both are
incorrect.

Selecting the range first makes no difference.

At one time these statements did actually return the right info. Not any
more.

I tried exporting the modules & the template styles to a new template (it
calls the aword document from another sub & then runs the addlineno code on
it), just in case there was corruption, but to no avail.

Can anyone give me a clue as to why the code isn't working?

Many thanks,

Terry.

----------------------------------------------------------------------------
--------------

The code: -

Sub AddLineNo()
Dim para As Paragraph, RngCur As Range, NewRng As Range, StrLineNo As String

If BoolEndRun = False Then
Set aword =
ActiveDocument.Range(ActiveDocument.Range.Bookmarks("BasFrm001").End,
ActiveDocument.Range.Bookmarks("Finish").Start)
StrLineNo = "Adding Line Numbers "
End If
On Error GoTo ErrHndlr
For Each para In aword.Paragraphs

Set RngCur = para.Range
With RngCur
Application.StatusBar = StrLineNo & .Information(wdActiveEndPageNumber) &
" - " & .Information(wdFirstCharacterLineNumber)

If Len(RngCur) >= 3 Then
..StartOf unit:=wdParagraph, Extend:=wdMove
Set NewRng = RngCur
NewRng.EndOf unit:=wdCharacter, Extend:=wdMove
If .Style = "Normal" Then

If BoolEndRun = True Then
StrLineNo = "Amending Line Numbers "

With RngCur
If .Font.Superscript = True Then

With NewRng
If .Font.Superscript = True Then
..MoveEnd unit:=wdCharacter, Count:=3
..Delete
End If
End With

End If
End With
End If

With .Font
..Superscript = True
..Size = 6
..ColorIndex = wdGray50
End With
End If
End If
End With
Next para

If BoolEndRun = True Then
Set aword = ActiveDocument.Range.Bookmarks("Finish").Range
aword.Delete
End If
BoolEndRun = True
Exit Sub

ErrHndlr:
Select Case Err.Number
Case 5251
'Reached end of range
Case Else
MsgBox Err.Number & ": " & Err.Description & vbCr & "occurred in Sub
AddLineNo"
End Select
End Sub
 
J

Jezebel

Terry Hornsby said:
I have some code which is supposed to add a string page & line No to the
start of each paragraph. During runtime if I hover the cursor over the
.information portion of the endpagenumber statement it returns a number one
less than if I hover it over the bracketed portion of the statement. The
code returns the first number. If this isn't bizarre enough, if I do the
same with the firstcharacter statement the first part returns a value of -1
& the bracketed bit returns a value of 10. The code returns -1, but both are
incorrect.

wdActiveEndPageNumber and wdFirstCharacterLineNumber are built-in constants.
Holding the mouse over those words displays their constant values (3 and 10
respectively). Holding the mouse over the .information returns the function
value, or -1 if the value is undefined. You get this for some Information
values for ranges within tables for example or not within the main story.

Which doesn't actually solve your problem. Can't see why your code isn't
functioning. Are you sure BasFrm001 and Finish are defined and that the
start of Finish is after the end of BasFrm001?
 
T

Terry Hornsby

The bookmark BasFrm001 is the first paragraph below the TOC. The bookmark
Finish is the last paragraph above the Index, so they're in the right order
& they do exist. The range loop does correctly identify the paragraphs in
this range (I erroneously left out the bit which inserts the page & line
numbers when I posted the code).

Word thinks the value is undefined, then. I had looked at the help file
which indicated -1 result for example when the range is in the header or
footer, but no mention is made of the main story giving anything but the
correct result.

I can only assume it doesn't because the main story is in two paragraph (not
table) columns.

Would you agree?

Many thanks,

Terry.
 
J

Jezebel

Word thinks the value is undefined, then. I had looked at the help file
which indicated -1 result for example when the range is in the header or
footer, but no mention is made of the main story giving anything but the
correct result.

I can only assume it doesn't because the main story is in two paragraph (not
table) columns.

I'd be wary of making such assumptions, but it certainly seems to be getting
something wrong. I've also had problems with the Information function -- my
conclusion was that it's a good old-fashioned bug in Word. Experiment with
the document format and see what happens.

If your document uses constant line-spacing you could determine the line
number by checking the vertical position and dividing by the vertical
spacing.
 
T

Terry Hornsby

Jezebel,

Thank you for the suggestion of the line spacing. I'll give this a go. At
the moment I am experimenting with using a loop to return the paragraph
number, but this presents problems of its own, as well!

Jezebel is an uncommon name these days. Is it a pseudonym, or is it real? I
changed my name from Terry Gary Broome to Terry Hornsby (no middle name)
because it got rid of a ridiculous half-rhyme & a clumsy name grouping.
There are five David's in the office where I work, but I've never come
across a Jezebel.

Best wishes,

Terry.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top