如何在 Outlook 2010 自定义表单中包含选定的电子邮件正文?

How to include selected email body in Outlook 2010 custom form?

我有一个自定义表单,用户在收到特定电子邮件时会使用该表单。我有 VBA 到 select 电子邮件并转发它,但我不知道如何将转发的电子邮件包含在自定义表单的电子邮件正文中。


更新:对于任何试图完成此任务的迷失灵魂,我已经找到了解决问题的方法。

Sub CustomForm_IncludesSelectedEmailBody()

Dim myOlApp As Application
Dim myNameSpace As NameSpace
Dim myFolder As MAPIFolder
Dim myItems As Items
Dim myItem As Object
Dim origEmail As MailItem


Set origEmail = ActiveExplorer.Selection(1)
Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myFolder = _
    myNameSpace.GetDefaultFolder(olFolderTasks)
Set myItems = myFolder.Items
Set myItem = myItems.Add("IPM.Note.DL_MALC_R_V1")
'the "IPM.Note.DL_MALC_R_V1" is the custom form's file name


myItem.HTMLBody = origEmail.Forward.HTMLBody
'this attaches the body of the email you're viewing to your new, forwarded email
myItem.Subject = origEmail.Forward.Subject
'This includes the selected email's subject line in your new email.
myItem.To = "emailYouWantToSendTo@example.com"
myItem.Display

Set myOlApp = Nothing
Set myNameSpace = Nothing
Set myFolder = Nothing
Set myItems = Nothing
Set myItem = Nothing
Set CustomForm = Nothing

End Sub

要为 运行 创建一个按钮 VBA,就像自定义功能区并将宏 select 设置为 运行 一样简单从那里开始。

/结束更新的答案


基本上我想要发生的是:

  1. 用户单击加载我的自定义表单的按钮
  2. 在步骤 1 中单击按钮后,select编辑或查看的电子邮件将包含在自定义表单的电子邮件正文中。

我的想法是将下面的 2 个代码部分与以下内容结合起来

Sub Combined()
    RunMyForm
    Forward
    'gets the forwarded email in the Forward sub, but doesnt include the body of the forwarded email in the custom form.
End Sub

它会起作用,但那没有发生。我是 VBA 的新手,所以我确定我在这里遗漏了一些东西。

创建按钮不是问题,因为这在 Outlook 本身中很容易做到。我在下面列出了 Sub Combined() 中的 2 个代码部分。

  1. VBA 拉取自定义表单。
Sub RunMyForm()
  Dim myOlApp As Application
  Dim myNameSpace As NameSpace
  Dim myFolder As MAPIFolder
  Dim myItems As Items
  Dim myItem As Object

  Set myOlApp = CreateObject("Outlook.Application")
  Set myNameSpace = myOlApp.GetNamespace("MAPI")
  Set myFolder = _
    myNameSpace.GetDefaultFolder(olFolderTasks)
  Set myItems = myFolder.Items
  Set myItem = myItems.Add("IPM.Note.Test1")
  myItem.Display

  Set myOlApp = Nothing
  Set myNameSpace = Nothing
  Set myFolder = Nothing
  Set myItems = Nothing
  Set myItem = Nothing
End Sub
  1. 选择当前查看的项目,转发,转发到指定邮箱。
Sub Forward()
'Combined with function GetcurrentItem, this forwards the selected email
    Dim fwd As Outlook.MailItem
    Dim itm As Object

    Set itm = GetCurrentItem()
    If Not itm Is Nothing Then
        Set fwd = itm.Forward
        fwd.Recipients.Add "email@exampleemail.com"
        fwd.Display
    End If

    Set fwd = Nothing
    Set itm = Nothing
End Sub
Function GetCurrentItem() As Object
    Dim objApp As Outlook.Application

    Set objApp = CreateObject("Outlook.Application")
    On Error Resume Next
    Select Case TypeName(objApp.ActiveWindow)
        Case "Explorer"
            Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
        Case "Inspector"
            Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
        Case Else
            ' anything else will result in an error, which is
            ' why we have the error handler above
    End Select

    Set objApp = Nothing
End Function

(在此处发布以便我可以将问题标记为已回答。抱歉,我是 Whosebug 的新手。)

更新:对于任何试图完成此任务的迷失灵魂,我已经找到了解决问题的方法。

Sub CustomForm_IncludesSelectedEmailBody()

Dim myOlApp As Application
Dim myNameSpace As NameSpace
Dim myFolder As MAPIFolder
Dim myItems As Items
Dim myItem As Object
Dim origEmail As MailItem


Set origEmail = ActiveExplorer.Selection(1)
Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myFolder = _
    myNameSpace.GetDefaultFolder(olFolderTasks)
Set myItems = myFolder.Items
Set myItem = myItems.Add("IPM.Note.CustomForm1")
'the "IPM.Note.CustomForm1" is the custom form's file name


myItem.HTMLBody = origEmail.Forward.HTMLBody
'this attaches the body of the email you're viewing to your new, forwarded email
myItem.Subject = origEmail.Forward.Subject
'This includes the selected email's subject line in your new email.
myItem.To = "emailYouWantToSendTo@example.com"
myItem.Display

Set myOlApp = Nothing
Set myNameSpace = Nothing
Set myFolder = Nothing
Set myItems = Nothing
Set myItem = Nothing
Set CustomForm = Nothing

End Sub