我必须每月创建并通过电子邮件将Excel文件发送给老板。我想使用VBA代码将文件作为附件发送,但是我的VBA代码不起作用,并且在确认后要求调试。
我的代码:
Sub EMail()
ActiveWorkbook.SendMail Recipients:="[email protected]"
End Sub
这是有关如何发送Active Workbook作为附件的示例
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 = "[email protected]"
.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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句