我必须每月创建一个 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/