Word

Email a Document Using Outlook

Ease of Use

Easy

Version tested with

2002 

Submitted by:

Jacob Hilderbrand

Description:

Programmatically email the active document. 

Discussion:

You need to email a document periodically and you are tired of doing this manually. VBA can do most of the work for you. This example uses Outlook to send the email. Assign the macro to a shortcut key, and you'll really get things going. 

Code:

instructions for use

			

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 .Send End With Application.ScreenUpdating = True Set Doc = Nothing Set OL = Nothing Set EmailItem = Nothing End Sub

How to use:

  1. Open your Word document.
  2. Press Alt + F11 to open VBE.
  3. Double click where is says "ThisDocument" on the project explorer.
  4. Insert-Module.
  5. Paste the code there in the window at right.
  6. Modify the code lines containing .Subject, .Body .To, and .Importance as needed.
  7. Set a reference to the Microsoft Outlook Object Library (Tools | References).
  8. Close VBE (Alt + Q or press the X in the top right hand corner).
  9. Save the file.
 

Test the code:

  1. Go to Tools-Macro-Macros and double-click eMailActiveDocument.
 

Sample File:

Email From Word.zip 7.18KB 

Approved by mdmackillop


This entry has been viewed 204 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express