将活动 Excel 工作簿的保存版本附加到电子邮件

问题描述 投票:0回答:1

我有一个 Excel VBA 代码附加到一个命令按钮,用于准备电子邮件供用户发送。

用户必须记住在按下按钮之前保存活动工作簿。这留下了太多的错误空间。

工作簿在附加之前如何保存?

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
excel vba outlook
1个回答
0
投票

当然,在发送电子邮件之前,您可以:

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

If ActiveDocument.Saved = False Then ActiveDocument.Save

您可能需要在前面添加

Application.DisplayAlerts = False
,这样您就看不到“您要保存吗”的通知,然后在后面添加
Application.DisplayAlerts = True
,以重新打开通知。

编辑:不清楚您是否从 Excel 运行此命令,我认为您是从 Excel 运行的。

© www.soinside.com 2019 - 2024. All rights reserved.