VBA for using Word Doc as Email Body

L

Lisab

I am looking for VBA code to use in Access 2007 that would use a word
document as the body of an email.

I am very well able to automate emails from access. I have created several
applications that automate email from within the access program using .oft
templates, attachments, and other customizations.

However, this client wants to be able to use word documents as the email
template.

Any help would be greately appreciated.
 
S

Sue Mosher [MVP]

This code is adapted from the sample at
http://www.outlookcode.com/codedetail.aspx?id=1333. It requires references
to both Outlook and Word libraries.

Sub SendDocAsMsg()
Dim wd As Word.Application
Dim doc As Word.Document
Dim itm As Outlook.MailItem
Dim ID As String
Dim blnWeOpenedWord As Boolean
On Error Resume Next

Set wd = GetObject(, "Word.Application")
If wd Is Nothing Then
Set wd = CreateObject("Word.Application")
blnWeOpenedWord = True
End If
Set doc = wd.Documents.Open _
(FileName:="C:\Current.doc", ReadOnly:=True)
Set itm = doc.MailEnvelope.Item
With itm
.To = "(e-mail address removed)"
.Subject = "My Subject"
.Send
End With
doc.Close wdDoNotSaveChanges
If blnWeOpenedWord Then
wd.Quit
End If

Set doc = Nothing
Set itm = Nothing
Set wd = Nothing
End Sub
 
L

Lisab

OH, Thank You Very Much!

Sue Mosher said:
This code is adapted from the sample at
http://www.outlookcode.com/codedetail.aspx?id=1333. It requires references
to both Outlook and Word libraries.

Sub SendDocAsMsg()
Dim wd As Word.Application
Dim doc As Word.Document
Dim itm As Outlook.MailItem
Dim ID As String
Dim blnWeOpenedWord As Boolean
On Error Resume Next

Set wd = GetObject(, "Word.Application")
If wd Is Nothing Then
Set wd = CreateObject("Word.Application")
blnWeOpenedWord = True
End If
Set doc = wd.Documents.Open _
(FileName:="C:\Current.doc", ReadOnly:=True)
Set itm = doc.MailEnvelope.Item
With itm
.To = "(e-mail address removed)"
.Subject = "My Subject"
.Send
End With
doc.Close wdDoNotSaveChanges
If blnWeOpenedWord Then
wd.Quit
End If

Set doc = Nothing
Set itm = Nothing
Set wd = Nothing
End Sub

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top