Sub Embed_Doc_In_new_mail()
'for support contact paul.sasur@hs.utc.com
'tools->references->Microsoft Outlook 11.0 Object Library
'tools->references->Microsoft Word 11.0 Object Library
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Dim RecipName As String
Dim WordApp As Word.Application
Dim OLbCreated As Boolean
'ignore any errors
On Error Resume Next
'attempt to capture an existing instance of Outlook
Set OutApp = GetObject(, "Outlook.Application")
're-set to stop on errors
On Error GoTo 0
'test to see if we successfully captured an existing instance of Outlook
If OutApp Is Nothing Then
'if no instance of outlook was found, create one
Set OutApp = CreateObject("Outlook.Application")
'remember that we created a new instance of outlook
OLbCreated = True
End If
'create a new mail item (message)
Set OutMail = OutApp.CreateItem(olMailItem)
'create a new instance of Word... doesn't matter if there is already
'an instance running, unlike Outlook, Word allows multiple instances
Set WordApp = CreateObject("word.application")
'set properties of the New Mail Item (Message)
With OutMail
.To = "John_Doe@yahoo.com"
.CC = ""
.BCC = ""
.Subject = "File Embedded"
'Body could be text, here we set the Content of an Existing Hardcodesd File
.Body = WordApp.Documents.Open("C:\Temp\word.doc").Content
'also can select a file from a dialog
' .Body = WordApp.Documents.Open(Application.GetOpenFilename(Title:="Please choose a file to import", FileFilter:="Word Files (*.doc),*.doc")).Content
'Can add files as attachments
' .Attachments.Add "C:\Temp\word.doc"
'use EITHER Send or Display Method, not both... send attempts to send in the
'background, while Display will show the message, requiring the user to
'click send
' .Send
.display
End With
'quit Outlook if we created a new instance, and reset object and item to nothing
If OLbCreated Then OutApp.Quit
Set OutMail = Nothing
Set OutApp = Nothing
'quit the new instance of Word we created, and set object to nothing
WordApp.Quit False
Set WordApp = Nothing
End Sub