0

I have these lines running to create a new email in Outlook. They are working well.

Now I want to make them work when I forwarded an email (instead of creating a new email) and also include the original email when I forwarded it.

How can I do that? Seems there’s only Application.CreateItem Method (Outlook) and no ForwardItem? Thank you.

Sub CreateMsg0()
Dim objMsg As MailItem

Set objMsg = Application.CreateItem(olMailItem)

 With objMsg
  .To = "Alias@domain.com; Alias111@domain.com; Alias222@domain.com"
  .CC = "Alias2@domain.com"
  .Subject = "This is the subject"

  .HTMLBody = "<p style='color:rgb(0,51,102);font-family:calibri;font-size:18'>" & ep _
              & "Hello," & "<br>" & "<br>" & "<br>" & ep _
              & "Email body writing line number 1." & "<br>" & ep _
              & "Email body writing line number 2." & "<br>" & ep _
              & "</p>" & ep _
              & "<br>" & "<br>" & "<br>" & ep _
              & "<p style='color:rgb(0,51,102);font-family:calibri;font-size:15'>" & ep _
              & "Signature line 1." & "<br>" & ep _
              & "Tel./fax." & "<br>" & ep _
              & "</p>"


  .Display

End With

Set objMsg = Nothing
End Sub
braX
  • 11,506
  • 5
  • 20
  • 33
Mark K
  • 8,767
  • 14
  • 58
  • 118
  • 1
    You don't want to create a new MailItem. You want to get a handle on an existing mail item and `.Forward` it. [Check this question out for possible example code.](https://stackoverflow.com/questions/28840066/forward-email-with-its-attachment-in-outlook-2010) – GMan80013 Jan 09 '18 at 05:22
  • @GMan80013, thank you for the guidance. – Mark K Jan 09 '18 at 06:48

1 Answers1

1

What is ep _ ? any way it should be Example

Option Explicit
Sub CreateMsg0()
    Dim objMsg As mailitem
    Dim Item As Outlook.mailitem

    Set Item = Application.ActiveExplorer.Selection.Item(1)

    Set objMsg = Item.Forward

    With objMsg
        .To = "Alias@domain.com; Alias111@domain.com; Alias222@domain.com"
        .CC = "Alias2@domain.com"
        .Subject = Item.Subject

        .HTMLBody = "<p style='color:rgb(0,51,102);font-family:calibri;font-size:18'>" _
                & "Hello," & "<br>" & "<br>" & "<br>" _
                & "Email body writing line number 1." & "<br>" _
                & "Email body writing line number 2." & "<br>" _
                & "</p>" _
                & "<br>" & "<br>" & "<br>" _
                & "<p style='color:rgb(0,51,102);font-family:calibri;font-size:15'>" _
                & "Signature line 1." & "<br>" _
                & "Tel./fax." & "<br>" _
                & "</p>" & "<BR>" & Item.HTMLBody

        .Display
    End With

    Set objMsg = Nothing
End Sub

For the Subject = .Subject = Item.Subject & Body & Item.HTMLBody

If you need the Recipients from original email then example would be

With objMsg
    .To = Item.To
    .CC = Item.CC
    .Subject = Item.Subject

MSDN MailItem.Forward Method (Outlook)

0m3r
  • 12,286
  • 15
  • 35
  • 71
  • very good! but it seems missed appended the "From:..Sent:...To:...Subject:..." parts of the original email? – Mark K Jan 09 '18 at 06:48
  • @MarkK Sorry I'm confused :-), you mean `Item.ReplyAll` https://stackoverflow.com/a/42805249/4539709 this? – 0m3r Jan 09 '18 at 07:02
  • thank you for the follow-up. I meant the first 4 lines (called header?) when people forwarded an email. the 4 lines are normally "From:..Sent:...To:...Subject:...". Is it because the line "...oMail.HTMLBody.." shall be "...& vbCrLf & oMail.HTMLBody..." etc? – Mark K Jan 09 '18 at 07:26