如何通过电子邮件发送Excel文件? [英] How can I send an Excel file via email?

查看:125
本文介绍了如何通过电子邮件发送Excel文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have to create and send an Excel file every month via email to my boss. I want to use a VBA code to send the file as attachment, but my VBA code doesn't work and asks for debug after confirmation.

我的代码:

Sub EMail() 
ActiveWorkbook.SendMail Recipients:="user@gmail.com" 
End Sub


推荐答案

以下是有关如何将Active Workbook作为附件发送的示例

Here is an example on how to send Active Workbook as attachment

Option Explicit
Sub EmailFile()
    Dim olApp As Object
    Dim olMail As Object
    Dim olSubject As String

'   // Turn off screen updating
    Application.ScreenUpdating = False

    Set olApp = CreateObject("Outlook.Application")
    Set olMail = olApp.CreateItem(olMailItem)

    olSubject = "This Subject Line"

    With olMail
        .Display
    End With

    With olMail
        .To = "0m3r@EMail.com"
        .CC = ""
        .BCC = ""
        .Subject = olSubject
        .HTMLBody = "This Body Text " & .HTMLBody
        .Attachments.Add ActiveWorkbook.FullName
        '.Attachments.Add ("C:\test.txt") ' add other file
'        .Send   'or use .Display
        .Display
    End With

'   // Restore screen updating
    Application.ScreenUpdating = True

    Set olMail = Nothing
    Set olApp = Nothing

End Sub

这篇关于如何通过电子邮件发送Excel文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆