lundi 20 avril 2015

E-Mail body is lost when sending (outlook vba)

I'm trying to write a macro that sends an automatic notification to specific addresses (kind of like a cc, but then without actually using cc) before sending the original email. The content of the original (formatted) email (including text, tables and pictures) should be copied and pasted into a new email which is then automatically sent. everything is works when just displying, but not when actually sending the email. the code is as follows:

Dim objMsg As Outlook.MailItem
Dim activeMailMessage As Outlook.MailItem
Dim BodyText As Object

' Create the message.
Set objMsg = Application.CreateItem(olMailItem)

'copy body of current item
Set activeMailMessage = ActiveInspector.CurrentItem
activeMailMessage.GetInspector().WordEditor.Range.FormattedText.Copy

'paste body into new email
Set BodyText = objMsg.GetInspector.WordEditor.Range
BodyText.Paste

'set up and send notification email
With objMsg
    .To = "test@domain.com"
    .Subject = "text" 
    .Send
End With

it was hard enough to find out how to do this to begin with, as pasting the text into the body like this:

With objMsg
    .To = "test@domain.com"
    .Subject = bodytext.paste 
    .Send
End With

would not paste any of the text at all (for no obvious reason to me).

when i use

    .display  

the right content is displayed, but when i send it, all of a sudden all information is lost and an empty email is sent. what can i do?

PS i realize i could add a bcc in the original email to achieve the same result, but the original email is not always send, whereas the notification should be.

Aucun commentaire:

Enregistrer un commentaire