Link to home
Start Free TrialLog in
Avatar of CafeTica
CafeTica

asked on

Word 2010/VBA: How to email Word doc as attachment and insert body text?

How do I use VBA or a Macro to send a new Outlook email from a Word doc that will attach the Word doc as an attachment and then include text in the body of the email?

Word 2010
Outlook 2010

Note: the body of the email will be a standard text like "Please see attached file."

Thank you
Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Easy enough and should be fairly self explanatory:

Sub sendeMail()
Dim olkApp As Object
Dim strSubject As String
Dim strTo As String
Dim strBody As String
Dim strAtt As String

    strSubject = "Whatever!"
    strBody = "Please see attached File"
    strTo = "fred@fred.com"
    If ActiveDocument.FullName = "" Then
        MsgBox "activedocument not saved, exiting"
        Exit Sub
    Else
        If MsgBox("Activedocument NOT saved, Proceed?", vbYesNo, "Error") <> vbYes Then Exit Sub
    End If
    strAtt = ActiveDocument.FullName
    
    Set olkApp = CreateObject("outlook.application")
    With olkApp.createitem(0)
        .to = strTo
        .Subject = strSubject
        .body = strBody
        .attachments.Add strAtt
        '.send
        .Display
    End With
    Set olkApp = Nothing
End Sub

Open in new window


swap the comment prefix ... ' ... from the display line to the display line to make it send automatically.

Chris
ASKER CERTIFIED SOLUTION
Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CafeTica
CafeTica

ASKER

Yes, easy to follow. Thanks