Forward Mail In attachment with VBA

adeel1
3StarLounger
Posts: 264
Joined: 04 Oct 2017, 15:47

Forward Mail In attachment with VBA

Post by adeel1 »

Hello All

i want to forward selected mail as attachment with the same mail subject of mail.
in body mail

Hello Team
please find attached for your ready work.

To, XXX@yahoo.com;zzz@Eileen.com

below is pic what i am trying to do, right now i am doing all this manually
Capture.PNG
Adeel
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78241
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Forward Mail In attachment with VBA

Post by HansV »

Does this do what you want?

Code: Select all

Sub ForwardAsAttachment()
    Dim objItem As Object
    Dim objMsg As MailItem

    Select Case TypeName(Application.ActiveWindow)
        Case "Explorer"
            Set objItem = Application.ActiveExplorer.Selection.Item(1)
        Case "Inspector"
            Set objItem = Application.ActiveInspector.CurrentItem
    Case Else
        Beep
        Exit Sub
    End Select

    Set objMsg = Application.CreateItem(olMailItem)

    With objMsg
        .Attachments.Add objItem, olEmbeddeditem
        .Subject = objItem.Subject
        .Body = "Hello Team" & vbCrLf & "Please find attached for your ready work."
        .To = "emailaddress1;emailaddress2"
        .Display ' or .Send if you want to send immediately
    End With
End Sub
Best wishes,
Hans

adeel1
3StarLounger
Posts: 264
Joined: 04 Oct 2017, 15:47

Re: Forward Mail In attachment with VBA

Post by adeel1 »

Prefect sir, :clapping: :clapping:
this is exactly what I want, Much Much thnx

Adeel