Re: inserting attachments into mailmerge emails

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



What is being copied and pasted into the mail message is the formatted letter/document created by the mail merge process for that recipient. It sounds like you might have missed the step of the instructions to execute that merge to a new document and with that document as the active document, run the macro.

--
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
"Alan" <alan.wright@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:9BCFD393-A4F2-4AD6-A44D-C25C47C6B3DF@xxxxxxxxxxxxxxxx
Hi Doug
I regret to say I could not get your modification to work. The attachements
works perfectly but now the mesage is totally blank except for the subject
and my personal signature (not part of the letter to merge). I can see the
theory of the change is to copy the main message before it gets changed, then
paste it back after the conflict but i have no idea about the language to use
or the cause of the conflict. In desperation I followed Graham's suggestion
and now have a temporary working solution. I really appreciate your help and
the speed of your response.

"Doug Robbins - Word MVP" wrote:

The following modified macro will preserve the graphics and formatting in
the messages:

Sub emailmergewithattachments()
'To create the email messages in
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")
'oOutlookApp.DefaultProfileName
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
' .cc = "Someone@xxxxxxxxxxxxx; Someoneelse@xxxxxxxxxxxxxxxxx"
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

' Close Outlook if it was started by this macro.
If bStarted Then
oOutlookApp.Quit
End If

MsgBox Source.Sections.Count - 1 & " messages have been sent."

'Clean up
Set oOutlookApp = Nothing

End Sub


--
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
"Alan" <alan.wright@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:059F9976-1E00-4640-810B-CE40548958F3@xxxxxxxxxxxxxxxx
> Until I saw Doug’s article “inserting attachments into mailmerge > emails”,
> I
> thought there was no way to send an attachment with an email from > Outlook
> 2003. I had been working on emailing a merged email message, with a
> second
> page containing what I really wanted to send as an attachment, and, due > to
> formatting problems on my internal test run and the scope for further
> problems with some of our unsophisticated prospect base, I had just > about
> given up on the whole idea.
>
> I have trialled Doug’s program with a work-around for the attachment > (in
> my
> case a .pdf form) and it works well, apart from one problem. I copied > and
> pasted the macro as directed, after specifying the References for the
> Tools
> Menu. I am using Outlook 2003 with Word 2003.
>
> Although my sent document and the inbox document (sent to myself for > the
> trial) both specify the document as HTML format, the document itself > has
> been
> stripped of graphics and the bold print and italic print. Everything
> appears
> as the original regular Ariel 10 font, similar to this print, with the
> bullets and tabs, removed. Is there a way to overcome this problem?
>
> If there has been a similar query before now, just point me to the
> comments
> and I will be very grateful.
>
> Alan
>



.



Relevant Pages

  • Re: inserting attachments into mailmerge emails
    ... 'To create the email messages in ... Dim Source As Document, Maillist As Document, TempDoc As Document ... ' Check if Outlook is running. ... Set oItem = oOutlookApp.CreateItem ...
    (microsoft.public.word.mailmerge.fields)
  • Re: Copy message body with formatting from Outlook to Word.
    ... HTML that includes formatting tags in addition to the actual text. ... "Outlook 2003 Inside Out" Chapter 26. ... Dim objWord As Word.Application ... Set objWord = CreateObject ...
    (microsoft.public.office.developer.outlook.vba)
  • Re: Table not included in email after merge
    ... 'To create the email messages in ... Dim source As Document, Maillist As Document, TempDoc As Document ... ' Check if Outlook is running. ... Set oItem = oOutlookApp.CreateItem ...
    (microsoft.public.word.mailmerge.fields)
  • Re: Formatting in attachment email merge (a la Doug Robbins)
    ... ' to be inserted into the email messages ... Dim source As Document, Maillist As Document, TempDoc As Document ... ' Check if Outlook is running. ... Set oItem = oOutlookApp.CreateItem ...
    (microsoft.public.word.mailmerge.fields)
  • RE: How to copy the format in word document to Outlook Mail
    ... Try setting Outlook to use Word as the e-mail editor for new messages and see ... formatting, neither does it display the table. ... Dim con As ADODB.Connection ...
    (microsoft.public.outlook.program_vba)