Re: sending emails from MS Word with variable subject line
Andy_F
:) Ok so adding a bookmark into 'TO' field is as simple as;
With Selection.GoTo(what:=wdGoToBookmark, Name:="EmailAddress")
Selection.MoveRight Unit:=wdWord, Count:=7, Extend:=wdExtend
myMailItem.To = Selection.Text
End With
instead of myMailItem.Recipient.Add ...
Thanks magicalclick, because before the message was just sending and closing the Outlook session, when I really wanted it to create the E-mail, leave it open for the user to check and send themselves.
.Display
.Save
its just what was needed. So I'm almost there!
Next, I need to (optional) add the Active Doc as an attachment, put in error handling for when the bookmarks don't exist and one thing I am stuck on is finding the end of the selection. i.e. with the code above you'll notice Count:=7. That's roughly the number of parts of an e-mail address as it includes several .dots, an @ symbols, and words. These bookmarks are in a table embedded in Word. I have been able to use ActiveDocument.Table(1).Cells(2,2).Range.Text to access the same data but there may be other tables entered into the doc hence using the unique bookmark names. Guess i'll just increase the count for each bookmark I'm using to a suitable maximum. One bookmark is a 'comments' field which could be up to 100-maybe even 200 words. Might have to compromise or have a rethink.
Thanks Andy & MagicalClick for your input, I rarely use Forums but I like this one !