Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2006

Tip: Looking for answers? Try searching our database.

Do not select paragraph mark

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
New to VBA - 24 Oct 2006 00:50 GMT
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
Jezebel - 24 Oct 2006 01:56 GMT
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?

> X-No-Archive: Yes
>
[quoted text clipped - 25 lines]
>
> Thanks
New to VBA - 25 Oct 2006 23:56 GMT
>>Term = replace(Term, vbcr, "")<<
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
Jezebel - 26 Oct 2006 00:17 GMT
In what sense didn't work?

> X-No-Archive: Yes
>
[quoted text clipped - 9 lines]
>
> Thanks
New to VBA - 27 Oct 2006 01:08 GMT
>>In what sense didn't work?<<

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
Jezebel - 27 Oct 2006 01:30 GMT
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?

> X-No-Archive: Yes
>
[quoted text clipped - 13 lines]
>
> Thanks
New to VBA - 28 Oct 2006 00:39 GMT
>>1) The Replace() function works in general -- what is it not doing that
>>you
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.

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

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!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.