Selecting text in a document

P

Phil Stokes

Hi, I have a macro which finds a certain piece of text in the document and
then moves down a line and then selects all the text between that and the end
of the document and the selected text is later sent out in an email. This has
been working for some time but I have recently had some problems because the
text is not being selected as before (extendmode on?) and I am sending out
blank emails.

The code fragment that I use to select the text is as follows

Selection.HomeKey wdStory
Selection.Find.Execute "Issued at"
Selection.MoveDown wdLine, 1
Selection.EndKey wdStory, wdExtend
Selection.Copy
varMessageStart = Selection


I have thought that there may be a problem when extendmode is in operation
(accidentlally) and the text is not being highlighted. I have thought of
trying to set a range from where the cursor is after the "find.execute" and
the "Linedown" to the end of the document and avoiding having to highlight
the text but I don't know how many characters will be in the first few lines
of the document.

Is there any way to set a range from the cursor point to the end of the
document.
or what is a foolproof way of ensuring that the extend mode is off and that
the selection will always include the text I want to copy?

Thanks

Phil
 
P

Pesach Shelnitz

Hi Phil,

Your code selects the text after a line containing "Issued at" until the end
of a document and copies it to the clipboard. It might be that you have
selected formatted text in Word and didn't clear the formatting. Your code
won't find the search string on such a computer. For this reason, calls to
Selection.Find.Execute should always be preceded by a call to ClearFormatting
as in the following.

Selection.HomeKey wdStory
Selection.Find.ClearFormatting
Selection.Find.Execute "Issued at"
Selection.MoveDown wdLine, 1
Selection.EndKey wdStory, wdExtend
Selection.Copy

The code that you provided does not show how the selected text is copied
into the e-mail messages, so I can't say that you don't have a problem in
that part of the code. For one thing, the last line that you sent doesn't
make any sense to me.
 

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