Sub SendMessage(DisplayMsg As Boolean, Optional AttachmentPath)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("Nancy Davolio")
objOutlookRecip.Type = olTo
' Set the Subject, Body, and Importance of the message.
.Subject = "This is an Automation test with Microsoft Outlook"
.Body = "This is the body of the message." &vbCrLf & vbCrLf
.Importance = olImportanceHigh 'High importance
' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
' Resolve each Recipient's name.
For Each ObjOutlookRecip In .Recipients
' Should we display the message before sending?
If DisplayMsg Then
Set objOutlook = Nothing
Trouble is, this only attaches an existing file. If I want to attach a report I'm currently viewing, how do i get it to save as pdf and then attach? SendObject is very good at this.
The pdf format is not natively supported in any version of the Office suite prior to Office 2007. If you want to work with pdf documents your choices are:
1. Work with Office 2007 where you can specify the pdf format as an argument of the SendObject method.
2. Work with a prior version of Office and install a third party component (usually a "pdf printer") that allow you to convert an Office document to the pdf format.
As for "don't wnat to install any extras like pdf printers etc", I guess you still have to install Office and your front-end on the users computers, so where is the problem?