Capturing in code the Rtf and Html of a merge document

M

Marketware

I would like to create mail merge letters in word and use those for outlook
as form emails after merging the data into the document. (one at a time so
the user can make any changes in the inspector before pressing send)

What is the appropriate properties from the word document that could give me
the rtf and the HTML code from the word document after it has been merged?

for example

outlookobject.HTMLbody = activedocument.??? //html email

outlookobject.RTFbody = activedocument.??? //rtf email

outlookobject.body = activedocument.??? //text email

Thanks in Advance!!

bob
 
D

Doug Robbins - Word MVP

The following code contains where indicated by the **** the commands
necessary to create such an email message. If you were to use something
similar and omit the .Send command, the email message will probably be
available for the user to edit it if necessary and then send it manually.

Dim Source As Document, Maillist As Document, TempDoc As Document
Dim DataRange As Range
Dim i As Long, j As Long
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
Dim mysubject As String, message As String, Title As String

Set Source = ActiveDocument

' Check if Outlook is running. If it is not, start Outlook
On Error Resume Next
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If

' Open the catalog mailmerge document
With Dialogs(wdDialogFileOpen)
.Show
End With
Set Maillist = ActiveDocument

' Show an input box asking the user for the subject to be inserted into the
email messages
message = "Enter the subject to be used for each email message." ' Set
prompt.
Title = " Email Subject Input" ' Set title.
' Display message, title
mysubject = InputBox(message, Title)

' Iterate through the Sections of the Source document and the rows of the
catalog mailmerge document,
' extracting the information to be included in each email.
For j = 1 To Source.Sections.Count - 1
Source.Sections(j).Range.Copy
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem
.Subject = mysubject
'****
.BodyFormat = olFormatHTML
.Display
Set objDoc = .GetInspector.WordEditor
Set objSel = objDoc.Windows(1).Selection
objSel.Paste
'****
Set DataRange = Maillist.Tables(1).Cell(j, 1).Range
DataRange.End = DataRange.End - 1
.To = DataRange
For i = 2 To Maillist.Tables(1).Columns.Count
Set DataRange = Maillist.Tables(1).Cell(j, i).Range
DataRange.End = DataRange.End - 1
.Attachments.Add Trim(DataRange.Text), olByValue, 1
Next i
.Send
End With
Set oItem = Nothing
Next j
Maillist.Close wdDoNotSaveChanges


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
M

Marketware

Thank you for responding to my question! I really appreciate it.

From your response then, I assume the best approach is to capture each
record via the clipboard?

What I am trying to do is capture the body of the merge document (merged)
like this:

Dear <<Saluation>>:

I hope all is well at <<Company_Name>>...

Convert it to:

Dear Fred:

I hope all is well at ABC Company...

And take the merged data and insert it into the body of the email.

Now the question I have from your response is...I notice you are attempting
to invoke the .WordEditor and you've set the format to HTML.

Is HTML the only format that this will work with reliably? Or can you do it
with Rich Text or Plain Text too? Also, can you set the Format on the fly or
are you limited to the message format the end user has set in his/her Options?

Thank you sooooooo much!!!

bob
 
D

Doug Robbins - Word MVP

The code that I posted captures the document created for each record in the
data source, not the record.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
M

Marketware

Thank-you yes, I realized that. Could you please respond to my questions?
Thank you.

bob
 
D

Doug Robbins - Word MVP

I do not know about RTF, but you can certainly do it in plain format as is
done in the code in the article "Mail Merge to E-mail with Attachments" at:

http://word.mvps.org/FAQs/MailMerge/MergeWithAttachments.htm

a version of that, which had been modified to create an email in HTML format
was the basis of the code that I posted.

The way in which the recipient views the email message is of course
dependent upon the way in which they have their newsreader configured.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 

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