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
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