I am using the answer (i.e. the code) to this question Working with current open email to build an email in steps. Every time I run the macro, it adds a piece of body text to the existing body text of an open email. The problem is that if I manually do some changes to the email between the macro "runs", then upon next run, the macro will insert the new body text building block where I left the cursor. But I want the macro to always add the new body text after the end of the existing (and expanding) body text. More specifically, this means that I (probably) need some code just before the line with the code "oSelection.InsertAfter myText" (see the code in the above link) that moves the cursor (insertion point) to the end of the open email that I am working with.
I have tried to play around with the SendKeys-command but using that I only manage to send the cursor to the end of the excel workbook sheet where I have the macro button. I want the cursor to end of the open email instead!
The macro leaves the cursor in the subject field. This will jump cursor down into the body, and move it to the end of the line:
Full Example:
Public Sub CreateNewMessage() Dim objMsg As MailItem
Set objMsg = Application.CreateItem(olMailItem)
With objMsg .To = "fake@example.com" .CC = "other@example.com" .BCC = "" .Subject = "Test email for you" .Categories = "" .VotingOptions = "" .BodyFormat = olFormatPlain ' send plain text message .Body = "Thank you for your submission. " .Display SendKeys "{Tab}{End}", True End With
Set objMsg = Nothing End Sub
References:
http://www.slipstick.com/developer/create-a-new-message-using-vba/
This line:
left an inactive cursor at the beginning of the body of my e-mail message. By manually tabbing, I noticed the cursor moving through the From, To, CC, BCC, etc. fields. It took 11 tabs, and 1 End to get the cursor to the end of a line of text in my e-mail. Silly though it seemed, I coded the extra tabs in, and it worked perfectly.
Ok, so I finally figured it out: