Hello,

I am searching for a way to attach a word file in a mail merge based
on an excel list. I come a long way but am stuck. Can someone please
help me tweak the code to get the job done?

Here is the code I came up with so far.

Sub Macro1()
    Dim OutApp As Object
    Dim OutMail As Object
    Dim cell As Range

    Application.ScreenUpdating = False
    Set OutApp = CreateObject("Outlook.Application")
    OutApp.Session.Logon

    On Error GoTo cleanup
    For Each cell In Columns("E").Cells.SpecialCells
(xlCellTypeConstants)
        If cell.Value Like "?...@?*.?*" And _
           LCase(Cells(cell.Row, "H").Value) = "ja" Then

            Set OutMail = OutApp.CreateItem(0)
            On Error Resume Next
            With OutMail
                .To = cell.Value
                .Subject = "Freelance opdrachten Yacht"
                .Body = "Beste " & Cells(cell.Row, "C").Value
                .Body = .Body & "Text." & vbNewLine
                'How to open a word document, change field in the
document into the firstname the e-mail is sent to, then save it and
attach it to the mail?
                .Attachments.Add "Location\filename.doc"
                .Send 'Or use Display
            End With
            On Error GoTo 0
            Set OutMail = Nothing
        End If
    Next cell

cleanup:
    Set OutApp = Nothing
    Application.ScreenUpdating = True
End Sub

Thanks a lot in advance!

--~--~---------~--~----~------------~-------~--~----~
----------------------------------------------------------------------------------
Some important links for excel users:
1. Excel and VBA Tutorials(Video and Text), Free add-ins downloads at 
http://www.excelitems.com
2. Excel tutorials at http://www.excel-macros.blogspot.com
3. Learn VBA Macros at http://www.vbamacros.blogspot.com
4. Excel Tips and Tricks at http://exceldailytip.blogspot.com
 

To post to this group, send email to excel-macros@googlegroups.com
If you find any spam message in the group, please send an email to:
Ayush Jain  @ jainayus...@gmail.com or
Ashish Jain @ 26may.1...@gmail.com
<><><><><><><><><><><><><><><><><><><><><><>
HELP US GROW !!

We reach over 5,200 subscribers worldwide and receive many nice notes about the 
learning and support from the group. Our goal is to have 10,000 subscribers by 
the end of 2009. Let friends and co-workers know they can subscribe to group at 
http://groups.google.com/group/excel-macros/subscribe
-~----------~----~----~----~------~----~------~--~---

Reply via email to