A macro to do this might be written as:
Sub EmailAsAttachment()
Dim bStarted As Boolean, OutlkApp As Outlook.Application, OutlkMlItm As Outlook.MailItem
' Check if Outlook is running. If it is not, start Outlook
If ThisDocument.Saved = False Then
MsgBox "ThisDocument has not been saved since the last edit." & vbCr & _
"Please save before emailing", vbExclamation
Exit Sub
End If
On Error Resume Next
Set OutlkApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set OutlkApp = CreateObject("Outlook.Application")
bStarted = True
End If
On Error GoTo 0
Set OutlkMlItm = OutlkApp.CreateItem(olMailItem)
With OutlkMlItm
.Subject = "Input the email message subject."
.Body = "Input the email message body."
.Recipients.Add "[email protected]"
.Attachments.Add Source:=ThisDocument.FullName, Type:=olByValue, Position:=1
.Send
End With
' Close Outlook if it was started by this macro.
If bStarted Then
OutlkApp.Quit
End If
'Clean up
Set OutlkMlItm = Nothing: Set OutlkApp = Nothing
MsgBox "Your message has been sent."
End Sub
Notes:
1. The host system must have Microsoft Outlook installed, even if not in use;
2. A reference to the Microsoft Outlook Object Library is required when you do the setup, using the oldest version of MS Office you plan to support;
3. The document must be saved in the the docm format or the doc format, not the docx format;
4. Within the 'With OutlkMlItm' ... 'End With' block there is provision for you to add an email title, body and, of course, the destination address; and
5. None of this will work if the user doesn't allow Word to run macros - and there's nothing you can do to force them to.
Bookmarks