Paragraphs (^p) for ^13?

D

Doug Robbins - Word MVP

Greg's site gives some examples of why you should not use ^13 in the replace
with section of the Edit>Replace dialog.

About the only time that you need to use ^13 in the Word User Interface is
in the Find what control when doing a Wildcard search.

If you want to insert a paragraph using vba, use vbCr

What are you really trying to do?

--
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, originally posted via msnews.microsoft.com
 
P

Peter Jamieson

However, in looking at these programmatically, how can you tell them
apart?

You can't if what you're looking at is range.text, because it's nothing
like a complete representation of what is in the range, and as you say,
both "paragraph marker character" and "CR character" come up as 13.

You would see the difference if you looked at either range.XML or
range.WordOpenXML, (you would see that - roughly speaking, a "paragraph"
is enclosed in <w:p> and </w:p>, but a "CR character" is represented by
a <w:cr/> within the "run" (<w:r> </w:r>) that contains the following
piece of text ( <w:t> </w:t> )

Unfortunately, if you use that approach then you would have to find ways
to ignore all the other stuff in there that you're not actually
interested in.

Without resorting to looking at XML, you could try incorporating
something along the following lines

Sub check13()
Dim i As Integer
Dim c As Word.Characters
Set c = Selection.Range.Characters
For i = 1 To c.Count
If AscW(c(i).text) = 13 Then
If c(i).Paragraphs(1).Range.End = c(i).End Then
Debug.Print CStr(i) & ": this 13 is a paragraph marker"
Else
Debug.Print CStr(i) & ": this 13 is not a paragraph marker"
End If
Set ce = Nothing
Else
Debug.Print CStr(i) & ": " & AscW(c(i))
End If
Next
Set c = Nothing
End Sub

Peter Jamieson

http://tips.pjmsn.me.uk
 
T

Tony Jollans

AFAIK, the bug (and it is a bug) in Find and Replace is the only way to
create this situation through the UI, and it isn't one you come across
often. What are you doing where the distinction makes a difference?

If it really does matter, one way to tell them apart would be to check if
they were the last character in the paragraph. If you have a Range, R,
containing just the character, then

If R.End = R.Paragraphs(1).Range.End Then
' It is a paragraph mark
Else
' It isn't
End If
 
G

Greg Maxey

Based on what Peter posted, you could use:

Sub ScratchMaco()
Dim oChr As Word.Range
Dim oRng As Word.Range
For Each oChr In Selection.Range.Characters
If Asc(oChr) = 13 Then
Set oRng = oChr
If Not InStr(oRng.XML, "<w:cr/>") > 0 Then
MsgBox "This is a true paragraph"
Else
MsgBox "This is a false paragraph"
End If
End If
Next
End Sub
 
G

George Lee

Wow. Thanks for everyone's comments.

Some have asked but this has become so rife in our group that I have to
routinely check for this since it throws formatting and styles off. We've had
this problem for a while and it never occured to me that find and replace was
the source. After asking around, it was obvious what all the other
writers/authors were doing. While I can educate them about this, it's still a
concern that has to be checked.
 
K

Klaus Linke

George Lee said:
Wow. Thanks for everyone's comments.

Some have asked but this has become so rife in our group that I have to
routinely check for this since it throws formatting and styles off. We've
had
this problem for a while and it never occured to me that find and replace
was
the source. After asking around, it was obvious what all the other
writers/authors were doing. While I can educate them about this, it's
still a
concern that has to be checked.

There's no reason why Word should allow ^13 in "Replace with"...
The Find/Replace dialog throws errors for a lot of other forbidden stuff.

Maybe someone will post that as a suggestion in the next Beta?
From my experience, there's only a slim chance that such a suggestion will
be acted on... But you never know until you tried <g>

Regards,
Klaus
 

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