selecting text in a document

P

Phil Stokes

Hi All,
I have a macro that seeks out a particular string of text in a document and
then moves down one line and selects the remaining text nin the document and
writes it to a variable and then uses it subsequently in the message section
of an email.

Recently this method has been failing because the text is not being
selected. I don't know if the PC was in EST mode a the time but I need the
macro to work no matter what. The code I use is as follows

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

I was considering replacing this code with code that creates a range from
the cursor to the end of the document and then writes that to the variable
but I don't know the character count down to the point that I wish to copy
from so.. my question is, is there code available that could create a range
as described above or would I be better trying something different. Is there
a way to ensure that the code above actually highlights the text and copies
it.
 
D

Doug Robbins - Word MVP

If the Issued at is in a separate paragraph, then you could use

Dim selrange As Range
Selection.HomeKey wdStory
If Selection.Find.Execute(FindText:="Issued at") Then
Set selrange = Selection.Range
selrange.End = ActiveDocument.Range.End
selrange.Start = selrange.Paragraphs(2).Range.Start
MsgBox selrange
End If


--
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
 

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