PDA

View Full Version : Solved: Email Active Document with Interaction



DDS
04-17-2008, 03:20 PM
Having a little bit of trouble working out the exact coding for a Word macro that can automatically launch outlook, fill in the TO:, Subject and Body text then attach the active document - but present the email to the user so they can edit the email body etc. if they choose before sending.
Anyone care to share their solutions with me?

lucas
04-17-2008, 04:46 PM
Requires a reference to the Outlook XX.0 Object Library
xx refers to your version of Office. mine is 11.0
In the VBE look at tools-Reference and place a check next to the one that is your version of Office.

Option Explicit
Sub eMailActiveDocument()
Dim OL As Object
Dim EmailItem As Object
Dim Doc As Document
Application.ScreenUpdating = False
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(olMailItem)
Set Doc = ActiveDocument
Doc.Save
With EmailItem
.Subject = "Insert Subject Here"
.Body = "Insert message here" & vbCrLf & _
"Line 2" & vbCrLf & _
"Line 3"
.To = "User@Domain.Com"
.Importance = olImportanceNormal 'Or olImprotanceHigh Or olImprotanceLow
.Attachments.Add Doc.FullName
.Display
' .Send
End With

Application.ScreenUpdating = True
Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing
End Sub

DDS
04-17-2008, 04:53 PM
Thanks,
That is what I thought would work too - but when I comment out the .Send it does nothing...

DDS
04-17-2008, 04:59 PM
But Ah-Ha! Change that to .Display...
Thanks again!

lucas
04-17-2008, 05:12 PM
Good eye DDS. Be sure to mark your thread solved using the thread tools at the top of the page.