If selection contains Chr(13) then...

R

Runt

If a selected sentence contains a carriage return (chr(13)) at the end
then I want the macro to to automatically drop it from the selection
using

Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend

But I have no idea how to identify whether there is such a character
and drop it without dropping the whole selection! Can you help?

Thanks in advance.

Chris
 
J

Jonathan West

Hi Runt

try this

If InStr(Selection.Text, Chr$(13)) > 0 Then
'Selection contains the character
Selection.MoveEnd Unit:=wdCharacter, Count:=-1
Else
'it doesn't
End If

--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com
 
J

Jezebel

If InStr(Selection.Text, Chr$(13)) > 0 Then
'Selection contains the character
Selection.MoveEnd Unit:=wdCharacter, Count:=-1
Else
'it doesn't
End If

Is it safe to assume that chr(13), if present, will be the last character in
the selection?
 
J

Jezebel

My point was that the proposed solution looks for chr(13) *anywhere* in the
selection, then removes the last character of the selection. So if chr(13)
were in the middle, it wouldn't be removed. But no problem if chr(13) is
always at the end, which might well be the case.




Runt said:
Jezebel,

The macro randomizes the order of words in a selected sentence, but it
wasn't working when the carriage return was selected. Unfortunatly, If
there is a carriage return at the end of the sentence, MS Word has a
habit of picking it up whether you want to or not!

Chris




Is it safe to assume that chr(13), if present, will be the last character in
the selection?
[/QUOTE]
 

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