当Outlookclosures时,在VBA,Excel中通过MS-Outlook发送带附件的电子邮件
当我从附件发送邮件,真正的作品。
但是当我使用.Attachments.Add ActiveWorkbook.FullName
参数时,它不会发送并等待打开Outlook。
我想在outlookclosures时发送邮件。
我使用下面的代码:
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)
:我希望电子邮件在运行macros1分钟后发送。
问候。
为什么这个问题是独特的原因:
- StackowerflowQuestion :这里的问题是在我上面的代码解决的,剩下的问题是发送附件 ,我在这里着重。 而且这个拨款的答案是我的口音就是Outlookclosures了。
更新
另一个症状是当我运行上面的代码时,临时图标将显示在try系统中,并popup消息: "another program is using outlook. to disconnect program and exit outlook..."
。
如果重要,请考虑这一点。
请注意,问题是发送附件 。
用上面的代码,解决了outlookclosures时发送邮件的问题。 (在类似的问题中提到)
所以剩下的问题是在这种情况下发送附件 (Outlookclosures)。
对不起,我刚刚误解了你的问题。 参考这里 ,你需要添加下面的代码。
Dim OutApp As Outlook.Application Dim OutMail As Outlook.MailItem On Error Resume Next Set OutApp = GetObject(, "Outlook.Application") If OutApp Is Nothing Then Set OutApp = CreateObject("Outlook.Application") End If On Error Goto 0 Set OutMail = OutApp.CreateItem(olMailItem) With OutMail .To = "address@domain.com" ' continue from here