I have been looking for a VBA that can send the entire workbook.
I found this
Sub Mail()
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 = "mymail@domain.com"
.CC = ""
.BCC = ""
.Subject = Range("A1").Value
.body = ""
.Attachments.Add ActiveWorkbook.FullName
.send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
But when opening the sent mail, the workbook is all empty. So I have to save the workbook before using VBA.
Is there a workaround for this, so it just work as normal File -> Save and send -> Send as attachment?
I'm assuming you don't want to save it so work with [ Application.Dialogs MSDN ]
Example 1
Option Explicit
Public Sub example()
Application.Dialogs(xlDialogSendMail).Show _
arg1:="mymail@domain.com", _
arg2:=Range("A1").Value
End Sub
Example 2 [ Workbook.SendMail MSDN ] Sends the workbook using installed mail system
Option Explicit
Public Sub example()
ActiveWorkbook.SendMail _
Recipients:=Array("mymail@domain.com", "mymail@domain.com"), _
Subject:=Range("A1").Value
End Sub
Or save your workbook before sending.
Example
ActiveWorkbook.Save .Attachments.Add ActiveWorkbook.FullName .send
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.