Email Word Document as Body of text

G

Guest

Hi,

I am trying to send a formatted word document as the body of an email from
VBA code. The following code will generate the email but how do I substitute
a simple string with a formatted Word document.

TIA

Richard

Set msg = appOutlook.CreateItem(olMailItem)

With msg
.To = strTo
.Subject = strSubject
.Body = strBody
.Display
End With
 
G

Guest

It is a bit fiddly, but doable. I don't know if you can do it directly from
word, but you can certainly do it if you save the word file as RTF.

Firstly, you need Outlook Redemption (http://www.dimastr.com/redemption) as
this will give you access to the RTF property of an email.

Below is a code sample (hastily hacked out of a project) I used for getting
RTF text into an Outlook appointment. Changing it for an email should be
fairly straightforward

Dim objApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder
Dim objDummy As Outlook.MailItem
Dim objRecip As Outlook.Recipient
Dim objAppt As Outlook.AppointmentItem
Dim objAppt2 As Outlook.AppointmentItem
Dim strMsg As String

Dim fso, f
Dim objContact As Object
Dim objContact2 As Object



On Error Resume Next



Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("C:\RTF_Temp.rtf", ForReading, True)


' ### name of person whose Calendar you want to use ###


Set objContact = CreateItem("Redemption.SafeMeetingItem")


Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
Set objDummy = objApp.CreateItem(olMailItem)
Set objRecip = objDummy.Recipients.Add(strCalendarName)

objRecip.Resolve
If objRecip.Resolved Then
On Error Resume Next
Set objFolder = _
objNS.GetSharedDefaultFolder(objRecip, _
olFolderCalendar)
If Not objFolder Is Nothing Then
Set objAppt = objFolder.Items.Add
If Not objAppt Is Nothing Then
Set objContact = New Redemption.SafeAppointmentItem
objContact.Item = objAppt
With objContact
.Subject = "Subject"
.Start = #1/1/2006#
.End = #1/1/2006#
.AllDayEvent = True
.rtfbody = f.ReadAll
.Save

End With

End If
End If
Else
MsgBox "Could not find " & Chr(34) & strCalendarName & Chr(34), , _
"User not found"
End If

Simon
 
G

Guest

Thanks Simon

I've heard about this Redemption and must look into it.

I managed to get it working so that from access I can run the mail merge and
then send the merged document as the body of the email. Many thanks for your
help and the pointer to Redemption.

Richie
 

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