创建电子邮件并附加其他整个电子邮

时间:2015-11-13 13:34:24

标签: vba outlook-vba outlook-2010

我正在尝试在Outlook中编写一个VBA代码,用于创建新的电子邮件,我已使用下面的代码完成了该操作。

我也想要一个附件。我想我必须以某种方式使用OutMail.Attachment.Method,但附件需要是特定的电子邮件。我不希望附加电子邮件中的附件,但我希望整个电子邮件包含内容(ie.texts,files.pics等)作为附件。

我想要做的只是附上我突出显示的任何电子邮件(作为.msg),然后创建电子邮件。

不确定如何做到这一点。任何帮助都会很棒!

Public Sub RemarkRequest()

Dim OutApp As Object
Dim OutMail As Object
Dim Signature As String

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next

'Get the user signature
With OutMail
    .Display
End With

Signature = OutMail.HTMLBody

'Change the mail address and subject in the macro before you run it.
With OutMail
    .To = "yyy@bbb.com; zzz@bbb.com"
    .CC = ""
    .BCC = ""
    .Subject = "Subject"
    .HTMLBody = "Text" & Signature
    .Display
End With

On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing

End Sub

1 个答案:

答案 0 :(得分:0)

示例将是 -

'// Forces explicit declaration of all variables in a file
Option Explicit
Sub ForwardAsAttchment()
    '//  Declare variables
    Dim olMsg As Outlook.MailItem
    Dim olItem As Outlook.MailItem
    Dim olSignature As String

    On Error Resume Next
    If Application.ActiveExplorer.Selection.Count = 0 Then
        MsgBox ("No Item selected")
        Exit Sub
    End If

    For Each olItem In Application.ActiveExplorer.Selection
        Set olMsg = Application.CreateItem(olMailItem)

        '// Get the user signature
        With olMsg
            .Display
        End With

        olSignature = olMsg.HTMLBody

        '// Change the mail address and subject in the macro before you run it.
        With olMsg
            .Attachments.Add olItem, olEmbeddeditem ' Attch Selected email
            .Subject = "Subject"
            .To = "yyy@bbb.com; zzz@bbb.com"
            .CC = ""
            .BCC = ""
            .HTMLBody = "Text" & olSignature
            .Display
        '    .Send
        End With
    Next
    '// Clean up
    Set olItem = Nothing
    Set olMsg = Nothing
End Sub