View Single Post
  #4   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Alan[_7_] Alan[_7_] is offline
external usenet poster
 
Posts: 3
Default inserting attachments into mailmerge emails

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 = ; "
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" wrote in message
...
Until I saw Dougs 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 Dougs 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