gpt4 book ai didi

vba - 在 Outlook 2010 中转发电子邮件及其附件

转载 作者:行者123 更新时间:2023-12-02 02:46:44 25 4
gpt4 key购买 nike

下面的代码(我从多个来源提取)现在可以工作,当我收到主题行中包含特定单词的电子邮件时,它会触发运行以下代码的脚本。

然后,此代码保留主题行,在邮件正文中添加文本,并将转发转发给目标收件人。

但是,如果我收到的电子邮件有附件,则代码将不再转发任何内容。我也需要它来转发通过电子邮件发送给我的附件(仅使用代码将文本添加到电子邮件正文,否则我只需设置规则)。

代码如下:

Sub ForwardEmail(item As Outlook.MailItem)
Dim oExplorer As Outlook.Explorer
Dim oMail As MailItem
Set oExplorer = Application.ActiveExplorer

On Error GoTo Release

If oExplorer.Selection.item(1).Class = olMail Then
Set oMail = item.Forward
oMail.Subject = oMail.Subject
oMail.HTMLBody = "Have a nice day." & vbCrLf & oMail.HTMLBody
oMail.Recipients.Add "email address here"


oMail.Save
oMail.Send

End If
Release:
Set oMail = Nothing
Set oExplorer = Nothing
End Sub

最佳答案

代码中不需要使用Explorer对象:

Sub ForwardEmail(item As Outlook.MailItem)
Dim oMail As MailItem

On Error GoTo Release

If item.Class = olMail Then
Set oMail = item.Forward
oMail.Subject = oMail.Subject
oMail.HTMLBody = "Have a nice day." & vbCrLf & oMail.HTMLBody
oMail.Recipients.Add "email address here"

oMail.Save
oMail.Send
End If
Release:
Set oMail = Nothing
Set oExplorer = Nothing
End Sub

您可能会找到Getting Started with VBA in Outlook 2010文章很有帮助。

关于vba - 在 Outlook 2010 中转发电子邮件及其附件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28840066/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com