Email. How do I place the cursor at the end of the body text?

I am using the answer (like code) to this question Working with current open mailto create an email step by step. Every time I run the macro, it adds some of the body text to the existing body text of the open email. The problem is that if I manually make some changes to the email between the "run" macros, then the next time I run the macro, it will add a new body text block where I left the cursor. But I want the macro to always add new body text after the end of the existing (and expanding) body text. More specifically, this means that I (perhaps) need some code just before the line with the code "oSelection.InsertAfter myText" (see the code in the link above) that moves the cursor (insertion point) to the end of the open email message with which I work.

I tried to play around with the SendKeys command, but using that I manage to send the cursor to the end of the sheet in the Excel workbook where I have the macro button. I want the cursor to end an open letter!

0


source to share


3 answers


Ok, so I finally figured it out:



  If oInspector.IsWordMail Then
            With NewMail
             .Display
             SendKeys "^+{END}", True
             SendKeys "{END}", True
             SendKeys "{NUMLOCK}"
            End With

      

0


source


The macro leaves the cursor in the subject field. This will move the cursor down to the body and move it to the end of the line:

SendKeys "{Tab}{End}", True

Complete 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

Literature:

http://www.slipstick.com/developer/create-a-new-message-using-vba/

0


source


This line:

SendKeys "{Tab}{End}", True

      

left an inactive cursor at the beginning of my email body. By manually tabbing, I noticed that the cursor moves through the From, To, CC, BCC, etc. fields. It took 11 tabs and 1 end to put the cursor at the end of a line of text in my email. Oddly enough, I coded additional tabs and it worked great.

With Mess
    .Display
    .Sensitivity = 3
    .To = Recip
    .bcc = "redacted recipient"
    .subject = subject
    .Attachments.Add Path & fileName & ".pdf"
    .HTMLBody = strbody & "<br>" & .HTMLBody
SendKeys "{Tab}{Tab}{Tab}{Tab}{Tab}{Tab}{Tab}{Tab}{Tab}{Tab}{Tab}{End}", True

      

0


source







All Articles