|
|
|
|
|
|
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
.Attachments.Add Doc.FullName
.Send
End With
Application.ScreenUpdating = True
Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing
End Sub
|
How to use:
|
- Open your Word document.
- Press Alt + F11 to open VBE.
- Double click where is says "ThisDocument" on the project explorer.
- Insert-Module.
- Paste the code there in the window at right.
- Modify the code lines containing .Subject, .Body .To, and .Importance as needed.
- Set a reference to the Microsoft Outlook Object Library (Tools | References).
- Close VBE (Alt + Q or press the X in the top right hand corner).
- Save the file.
|
Test the code:
|
- 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 205 times.
|
|