【发布时间】:2017-03-28 01:55:35
【问题描述】:
我们目前有一封由 Excel 使用 VBA 自动创建的电子邮件,主题、收件人、邮件正文以及模板文本均已填写。
Sub CreateMail(Optional sFile As String = "")
'Create email to send to requestor with attachment sFile
'Declarations
Dim app As Outlook.Application
Dim msg As Outlook.MailItem
Dim send_to As Recipient
Dim send_tos As Recipients
'Initiations
Set app = CreateObject("Outlook.Application")
Set msg = app.CreateItem(olMailItem)
Set send_tos = msg.Recipients
Set send_to = send_tos.Add("receiver@email.com")
send_to.Type = 1
'Create message
With msg
.SentOnBehalfOfName = "sender@email.com"
.Subject = "This is the email subject"
.HTMLBody = "This is the email body" & vbCrLf
'Resolve each Recipient's name.
For Each send_to In msg.Recipients
send_to.Resolve
Next
If Len(sFile) > 0 Then
.Attachments.Add sFile
End If
.Display
End With
End sub
在对创建的电子邮件进行一些手动更改后,我们希望将其发送并自动将副本保存到文件系统上的文件夹中(除了 Outlook 中通常发送的文件夹之外)。有没有办法在 Excel VBA 中完成这一切?
我怀疑使用 Outlook VBA 可能是可行的,但是文件夹是在 Excel 中定义的,我们希望将代码一起保存在一个文件中。
【问题讨论】:
-
我们特别希望使用 Excel VBA 进行保存。
-
如果您添加对 Microsoft Outlook 对象模型的引用,则 Excel VBA 可以使用其他答案中提到的方法。如果您不确定在哪里看,也许这会更好地作为答案?
-
在链接解决方案中,电子邮件在 Outlook 中被选中,然后保存到文件夹中。而我是在从 Excel 创建的电子邮件触发发送事件后将电子邮件保存到文件夹之后。
-
好的,没问题。那不是骗子