excel - 如何通过电子邮件发送 Excel 文件?

标签 excel vba email email-attachments

我必须每月创建一个 Excel 文件并通过电子邮件发送给我的老板。 我想使用 VBA 代码将文件作为附件发送,但我的 VBA 代码不起作用,并要求在确认后进行调试。

我的代码:

Sub EMail() 
ActiveWorkbook.SendMail Recipients:="<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5a2f293f281a3d373b333674393537" rel="noreferrer noopener nofollow">[email protected]</a>" 
End Sub

最佳答案

应得的信用...这直接来自 Ron de Bruin网站。

Sub Mail_workbook_Outlook_1()
'Working in Excel 2000-2016
'This example send the last saved version of the Activeworkbook
'For Tips see: https://www.rondebruin.nl/win/s1/outlook/tips.htm
    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 = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="89fbe6e7c9edecebfbfce0e7a7e7e5" rel="noreferrer noopener nofollow">[email protected]</a>"
        .CC = ""
        .BCC = ""
        .Subject = "This is the Subject line"
        .Body = "Hi there"
        .Attachments.Add ActiveWorkbook.FullName
        'You can add other files also like this
        '.Attachments.Add ("C:\test.txt")
        .Send   'or use .Display
    End With
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub

关于excel - 如何通过电子邮件发送 Excel 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35829348/

相关文章:

email - 如何从 Google Cloud 通过 G-suite 发送电子邮件

excel - 四阶和五阶多项式回归在 Excel 中不起作用

excel - 运行时错误 1004 - Excel 找不到用于刷新此外部数据范围的文本文件

arrays - VBA 中的最长公共(public)子序列给出#VALUE!错误

excel - 将富文本格式转换为 HTML 格式标签

java - 如何从菜单发送电子邮件?

java - MimeMessage 中的智能引号未在 Outlook 中正确显示

excel - 使用 Outlook 发送邮件时隐藏屏幕更新

excel - 从一行中获取 value > 0 的所有列的逗号分隔列标题

vba - 循环数字以创建一个大表