Selection containing complete paragraphs?

A

Alex

How can I ascertain that a selection contains only complete paragraphs?

E.g, given the sample text:

123456789<para>
123456789<para>
123456789<para>
123456789<para>
123456789<para>

The selection should start at a '1' character and end either at a '<para>' paragraph mark or at a '9' character (in that case I need to automatically extend it to the immediately following paragraph mark.

Also, selecting a complete table cell should also qualify (whether it contains multiple paragraphs or even a single character).

I'd like to also test for the opposite condition: that the selection does not contain any paragraph mark (and, if it is in a table cell, it does not encompass the whole cell).

Thank you.


Best wishes,
Alex.
 
D

Doug Robbins

Dim myrange as range
Set myrange=Selection.Range
If myrange.End = myrange.Paragraphs(1).Range.End Then
MsgBox "The selection encompasses the end of the paragraph"
End if

For the tables part, check out the Selection.Information function.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
How can I ascertain that a selection contains only complete paragraphs?

E.g, given the sample text:

123456789<para>
123456789<para>
123456789<para>
123456789<para>
123456789<para>

The selection should start at a '1' character and end either at a '<para>'
paragraph mark or at a '9' character (in that case I need to automatically
extend it to the immediately following paragraph mark.

Also, selecting a complete table cell should also qualify (whether it
contains multiple paragraphs or even a single character).

I'd like to also test for the opposite condition: that the selection does
not contain any paragraph mark (and, if it is in a table cell, it does not
encompass the whole cell).

Thank you.


Best wishes,
Alex.
 
H

Helmut Weber

Hi Alex,
that's at lot at once. You better split it all up
in different functions (and questions). And your post
seems not to consider that you might want to know, whether
the selection contains whole paragraphs in a cell.
Just to set up the principle, with lots of problems
in detail yet to come, disregarding an extention of the range,
if the next character is a paragraph mark.
Not too difficult, though.
---
Public Function WholeParagraphsOnly(oRng As Range) As Boolean
Dim p1 As Long ' start of first paragraph in selection
Dim p2 As Long ' end of last paragraph in selection
Dim s1 As Long ' start of selection
Dim s2 As Long ' end of selection
p1 = oRng.Paragraphs.First.Range.Start
p2 = oRng.Paragraphs.Last.Range.End
s1 = oRng.Start
s2 = oRng.End
If p1 = s1 And p2 = s2 Then
WholeParagraphsOnly = True
End If
End Function
Sub testit()
Dim rtmp As Range
Set rtmp = Selection.Range
MsgBox WholeParagraphsOnly(rtmp)
End Sub

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
A

Alex

Hello Doug and Helmut,

This should work, thank you.

I need to get more more comfortable with Word's object model...


Best wishes,
Alex.
 

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