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
 
Joined
Dec 13, 2005
Messages
1
Reaction score
0
.introduction property for MailEnvelope

Thanks, Sue, for your posting here - it helped me solve an issue with sending Word documents as emails from access database of addresses.

However, I have a question about the .introduction property for MailEnvelope. This feature allows the programmer to put a message at the front of the e-mail body. I have got this to work, but I cannot find any way to change its font. Despite the defaults in both Word and Outlook I find the introduction is in what looks like Times Roman.

Do you know anyway to set the font for the introduction?

Any help gratefully received,
Fergus
 

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