detection of end-of-paragraph

  • Thread starter Martin Müller
  • Start date
M

Martin Müller

Dear experts

how can I detect an end-of-paragraph sign, namely ChrW(10)? I want to extend a selection as far as the next blank appears or the next end-of-paragraph sign through

Do While Not (Selection.Text Like "* *" Or Selection.Text Like "*" & ChrW(10) & "*"
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExten
Loo

but the loop recognizes blanks only
Best regard
Martin
 
H

Helmut Weber

Hi Martin,
there are of many ways to do that.
A quite simple approach could be:
Selection.ExtendMode = True
Do Until _
(Right(Selection.text, 1) = " " Or _
Right(Selection.text, 1) = Chr$(10))
Selection.MoveRight
Loop
But Chr$(10) is not a paragraph mark.
You may use VBCR, vBCRLF, or "^a" (word 97) or
"^p" (higher versions) or chr$(13).
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, NT 4.0
 
B

Bruce Brown

Martin

As Helmut says, there are many ways to do this. The range
object's MoveEndUntil method is as simple and flexible as any:

Dim R As Range
Set R = Selection.Range
'To select to *either* the next blank space or the next paragraph _
mark, whichever comes first, use this:
R.MoveEndUntil " " & vbCr
'To select to the next blank space, use this:
R.MoveEndUntil " "
'To select to the next paragraph mark, use this:
R.MoveEndUntil vbCr
'To move the selection one character beyond where it stops:
R.End = R.End + 1
'Last but not least, to do the actual selection:
R.Select

- Bruce
 

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