Do not select paragraph mark

N

New to VBA

X-No-Archive: Yes

I have this macro that when the user selects a term or sentence in a
document, then
it pastes it to an external application and does its thing. The macro begins
with:

Dim Term As String
If Selection.Type = wdSelectionIP Then
Term = Selection.Words(1).Text
Else
Term = Selection.Text
End If
Term = Trim(Term)
'Open the external application, etc....

The problem is that if the selected text is at the end of a line or
paragraph
and includes the line or paragraph mark, then it pastes the term but the
macro stops running. If the selection does not include a paragraph mark, the
macro runs normally and works flawlessly.

What is the code not to include the paragraph mark in the selection (i.e.,
if the selected text
includes a paragrah mark, then move one space to the left)?

Thanks
 
J

Jezebel

Might be simpler just to remove the paragraph mark:

Term = replace(Term, vbcr, "")

There might be other characters you don't want either, or that need to be
escaped (depending on your external app) - like vbLF, vbTab, chr(34), etc.

What should happen if the user has selected several paragraphs?
 
N

New to VBA

X-No-Archive: Yes
There might be other characters you don't want either,
What should happen if the user has selected several paragraphs?<<

I'm afraid it did not work, and no, there are no other characters I dont't
want either and the users never select more than one paragraph.

I guess I'll just tell the users not to include the paragraph mark in the
selected text

Thanks
 
J

Jezebel

In what sense didn't work?



New to VBA said:
X-No-Archive: Yes

There might be other characters you don't want either,
What should happen if the user has selected several paragraphs?<<

I'm afraid it did not work, and no, there are no other characters I dont't
want either and the users never select more than one paragraph.

I guess I'll just tell the users not to include the paragraph mark in the
selected text

Thanks
 
N

New to VBA

X-No-Archive: Yes

By that I mean what I said in my first message: the macro pastes the term in
the external application but stops running. If the selection does not
include a paragraph mark, the macro continues to run normally to the end and
works flawlessly.

That is, the line

SendKeys Term & "{ENTER}", True

send the Term but does not send the "{ENTER}" key

Thanks
 
J

Jezebel

1) The Replace() function works in general -- what is it not doing that you
need in this case?

2) Why on earth are you buggering around with SendKeys?
 
N

New to VBA

X-No-Archive: Yes
need in this case?<<

As I said in my previous post, in the line SendKeys Term & "{ENTER}", True
the macro sends the Term to the search window of the application and stops
there, it does not send "{ENTER}" and the user has to manually press the
Enter key , if the selected text (the Term) does not include a paragraph
mark, then everything works OK, the macro places the Term and "presses"
Enter.


LOL!, I need to place the term in the search window of the external
application, but I discovered that a simple Selection.Paste worked, with and
without the paragraph mark, so I changed the code to SendKeys "^V" &
"{ENTER}", True and now everything works.

Thanks!
 

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