VBA for using Word Doc as Email Body

Status
Not open for further replies.
T

TGlzYWI

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 = "someone@somewhere.com"

> 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

"Lisab" <Lisab> wrote in message

news:6935A534-300B-4713-8D2C-A07285E908D7@microsoft.com...
> 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.
 
T

TGlzYWI

OH, Thank You Very Much!

"Sue Mosher [MVP]" wrote:


> 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 = "someone@somewhere.com"
> .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
> > >

> "Lisab" <Lisab> wrote in message
> news:6935A534-300B-4713-8D2C-A07285E908D7@microsoft.com...
> >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.


>
 
Status
Not open for further replies.
Top