Sneding email thru VBA (using Exchange)
Hi,
add references : microsoft outlook xxxx object library
if you want to send your shet mail body use this code :
Sub mailsend()
' Requires reference to Microsoft Outlook
Dim ws As Worksheet, env As MsoEnvelope, mi As MailItem
' Get the active worksheet.
Set ws = ActiveSheet
' Save the workbook before mailing as attachment.
ws.Parent.Save
' Show email header.
ws.Parent.EnvelopeVisible = True
' Get the MsoEnvelope object
Set env = ws.MailEnvelope
' Set the email header fields.
' env.Introduction = "Please revew attached file."
' Get the MailItem object.
Set mi = env.Item
' Clear the MailItem properties.
ClearMessage mi
' Set MailItem properties.
mi.Importance = olImportanceHigh
' Set MailItem properties ImportanceHigh.
mi.SentOnBehalfOfName = "
' Set MailItem sender if use different sender.
mi.To = "
mi.CC = "
mi.Subject = "Subject text in here"
' Attach this workbook.
mi.Attachments.Add "d:\sample.pdf" ''ThisWorkbook.FullName
' Uncomment this to send automatically.
mi.Send
End Sub
and if you want to send your any document, use :
mi.Attachments.Add
|