Setting focus back to document from email header

J

Jules

Hi,

I am trying to set up a macro which opens the email header in a Word
document and then copies some text from the document to the "To" line and the
"Subject" line.

So far I have the following

Selection.HomeKey unit:=wdStory
Selection.EndKey unit:=wdLine, Extend:=wdExtend
Selection.Cut
ActiveWindow.EnvelopeVisible = Not ActiveWindow.EnvelopeVisible
Selection.Paste

This works fine to copy the first line of the document (the email address)
into the "To" line of the email, however, I now can not work out the code to
set the focus back to the document to copy/cut the Subject text and then set
the focus to the "Subject" line to paste. I have tried setting bookmarks in
the document and going back to them, but this doesn't seem to work - my
cursor just stays in the "To" line of the email header.

Does anyone have any suggestions on how to do this please?

Thanks for your help
 
C

Chip Orange

Well, following your same methods, you could add:

ActiveDocument.content.paragraphs(1).range.select
Selection.Collapse wdCollapseStart

which should put you back at the beginning of the document; but I think
you're going to have trouble then getting info in the other various envelope
fields.

The difficulty is in this method of moving the cursor around where you want
the info to come from or go to; it's better, although a lot more learning
curve, to learn to use the object model and reference these locations
directly, and not move the cursor around at all.

I referenced the first paragraph of the document above just as an example.

hth,

Chip
 

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