how to detect that the end of a range is also end of a paragraph?

G

Graham Mayor

There are several ways including:

Test whether the range and the last paragraph in the range have the same end
eg

If oRng.End = oRng.Paragraphs.Last.Range.End Then
'the range end is also a paragraph end.
End If

or see what the last character of the range is e.g.

If oRng.Characters.Last = Chr(13) Then
'the range end is also a paragraph end
End If
or
If oRng.Characters.Last = vbCr Then
'the range end is also a paragraph end
End If

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
M

macropod

Hi Graham,

Not quite! Try selecting the 'paragraph mark' that defines the end of a table cell, then run the following macro:
Sub Test()
'Graham's test
MsgBox Selection.Characters.Last = Chr(13)
'Macropod's test
MsgBox Asc(Selection.Characters.Last) = 13
End Sub
 
G

Graham Mayor

It could be argued that the table cell end marker is not a paragraph mark,
but I take your point. :)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


macropod said:
Hi Graham,

Not quite! Try selecting the 'paragraph mark' that defines the end of a
table cell, then run the following macro:
Sub Test()
'Graham's test
MsgBox Selection.Characters.Last = Chr(13)
'Macropod's test
MsgBox Asc(Selection.Characters.Last) = 13
End Sub

--
Cheers
macropod
[Microsoft MVP - Word]


Graham Mayor said:
There are several ways including:

Test whether the range and the last paragraph in the range have the same
end eg

If oRng.End = oRng.Paragraphs.Last.Range.End Then
'the range end is also a paragraph end.
End If

or see what the last character of the range is e.g.

If oRng.Characters.Last = Chr(13) Then
'the range end is also a paragraph end
End If
or
If oRng.Characters.Last = vbCr Then
'the range end is also a paragraph end
End If

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Greg Maxey

Sub ScratchMaco()
Dim oDoc As Word.Document
Set oDoc = Documents.Add
oDoc.Tables.Add oDoc.Range, 1, 1
MsgBox oDoc.Paragraphs.Count
End Sub

Both the end of cell and the end of row are counted as a parapraph :-(


Graham said:
It could be argued that the table cell end marker is not a paragraph
mark, but I take your point. :)


macropod said:
Hi Graham,

Not quite! Try selecting the 'paragraph mark' that defines the end
of a table cell, then run the following macro:
Sub Test()
'Graham's test
MsgBox Selection.Characters.Last = Chr(13)
'Macropod's test
MsgBox Asc(Selection.Characters.Last) = 13
End Sub

--
Cheers
macropod
[Microsoft MVP - Word]


Graham Mayor said:
There are several ways including:

Test whether the range and the last paragraph in the range have the
same end eg

If oRng.End = oRng.Paragraphs.Last.Range.End Then
'the range end is also a paragraph end.
End If

or see what the last character of the range is e.g.

If oRng.Characters.Last = Chr(13) Then
'the range end is also a paragraph end
End If
or
If oRng.Characters.Last = vbCr Then
'the range end is also a paragraph end
End If

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Hi,

how to detect that the end of a range is also end of a paragraph?
 

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