Thread: [Solved] Can't merge mail from Excel
View Single Post
 
Old 04-04-2014, 04:01 PM
Mahmed1 Mahmed1 is offline Windows 7 64bit Office 2010 32bit
Novice
 
Join Date: Apr 2014
Posts: 17
Mahmed1 is on a distinguished road
Default Can't merge mail from Excel

Hi,

What is wrong with code :-(

Nothing is happening with this code

All i am trying to do is from my excel worksheet (Active worksheet)
Mail merge Sheet 1 /Letters/Address block/Finish merge and rather than send to new document, send to document i am opening.

Is there any bits of code i can take out

I also have a Named range called Address to mail merge if that helps but if not then the range is on sheet1

Here is my code
Code:
Sub RunMerge() 
    Dim strWorkbookName As String 
    Dim wdapp As Word.Application 
    Set wdapp = New Word.Application 
    Dim wddoc As Word.Document 
    Set wddoc = wdapp.Documents.Add 
    strWorkbookName = ThisWorkbook.Path & "\" & ThisWorkbook.Name 
    With wddoc.MailMerge 
        .MainDocumentType = wdFormLetters 
        .OpenDataSource _ 
        Name:=strWorkbookName, _ 
        AddToRecentFiles:=False, _ 
        Revert:=False, _ 
        Format:=wdOpenFormatAuto, _ 
        Connection:="Data Source=" & strWorkbookName & ";Mode=Read", _ 
        SQLStatement:="SELECT * FROM 'Sheet1'" 
        .Destination = wdSendToNewDocument 
        .SuppressBlankLines = True 
        With .DataSource 
            .FirstRecord = wdDefaultFirstRecord 
            .LastRecord = wdDefaultLastRecord 
             'Add address block field and update
        End With 
    End With 
    wd.Visible = True 
End Sub

Last edited by macropod; 04-04-2014 at 04:59 PM. Reason: Added code tags & formatting
Reply With Quote