2016-09-29 136 views
0

我有一个宏附加到命令按钮,用于准备用户发送的电子邮件。问题是,用户必须记住在按下发送按钮之前保存文档。我宁愿不依赖用户记住保存,它留下太多的错误空间。在SendEmail宏之前是否可以输入一个宏来自动保存文档?这是我到目前为止有:宏将文件的保存版本附加到电子邮件

Sub SendEmail() 
Dim OutApp As Object 
Dim OutMail As Object 

Set OutApp = CreateObject("Outlook.Application") 
Set OutMail = OutApp.CreateItem(0) 

On Error Resume Next 
With OutMail 
    .to = "me" 
    .Subject = "Completed Testing Schedule " & Date 
    .Attachments.Add ActiveWorkbook.FullName 
    .Display 
End With 
On Error GoTo 0 

Set OutMail = Nothing 
Set OutApp = Nothing 
End Sub 

回答

0

当然,您发送电子邮件之前,你可以这样做:

Documents.Save NoPrompt:=True, OriginalFormat:=wdOriginalDocumentFormat

If ActiveDocument.Saved = False Then ActiveDocument.Save

您可能希望在此之前加上Application.DisplayAlerts = False,所以你没有看到那个通知“你想保存”,然后把Application.DisplayAlerts = True之后,重新开启通知。

编辑:这是不清楚,如果你从Excel运行这,我认为你是。

+0

我从Excel运行此并且您的解决方案工作!谢谢。 – ZiggyStarlust

相关问题