当我从附件免费发送邮件时,真正地工作 .
但是当我使用 .Attachments.Add ActiveWorkbook.FullName
参数时,它不会发送并等待打开Outlook .
I want send mails when outlook is closed.
我正在使用以下代码:
Sub SendMail()
Dim OutlookApp As Outlook.Application
Dim OutlookMail As Outlook.MailItem
Set OutlookApp = New Outlook.Application
Set OutlookMail = OutlookApp.CreateItem(olMailItem)
With OutlookMail
.To = "address@domain.com"
.CC = ""
.BCC = ""
.Subject = "M"
.BodyFormat = olFormatHTML
.HTMLBody = "Hi, <p> I'm sending this message from Excel using VBA.</p>Please find <strong> M</strong> in life."
.Attachments.Add ActiveWorkbook.FullName
.DeferredDeliveryTime = DateAdd("n", 1, Now)
.Importance = olImportanceHigh
.ReadReceiptRequested = True
.Send
End With
Set OutlookMail = Nothing
Set OutlookApp = Nothing
End Sub
关于 .DeferredDeliveryTime = DateAdd("n", 1, Now)
:我希望电子邮件在运行宏后1分钟发送 .
问候 .
为什么这个问题是独一无二的原因:
- StackowerflowQuestion:这里的问题在上面的代码中解决了,剩下的问题是我在这里专注的 sending attachment . 而且我认为适当的答案是 Outlook is closed.
更新
另一个症状是,当我在代码上运行时,try系统中会显示一个临时图标,并显示一条弹出消息: "another program is using outlook. to disconnect program and exit outlook..."
.
如果重要的话,还请考虑这个 .
请注意,问题是 sending attachment .
使用上面的代码,解决了Outlook关闭时发送电子邮件的问题 . (在类似的问题中提到)
因此,在这种情况下,剩下的问题是 sending attachment (Outlook已关闭) .
1 回答
对不起,我刚刚误解了你的问题 . 参考here,您需要添加以下代码 .