![]() |
#27
|
|||
|
|||
![]() Quote:
I have attached the coding I used from the tutorial doc. Since Im having difficulty attaching, could you not start a new word doc, start directory merge - copy and paste the code across and then paste this code into the developer: Code:
Sub RunMerge() Application.ScreenUpdating = False Dim Doc1 As Document, Doc2 As Document, Doc3 As Document, StrDoc As String Set Doc1 = ThisDocument StrDoc = ThisDocument.Path & "\EmailDataSource.doc" If Dir(StrDoc) <> "" Then Kill StrDoc With Doc1.MailMerge If .State = wdMainAndDataSource Then .Destination = wdSendToNewDocument .Execute Set Doc2 = ActiveDocument End If End With Call EmailMergeTableMaker(Doc2) With Doc2 .SaveAs FileName:=StrDoc, AddToRecentFiles:=False, FileFormat:=wdFormatDocument StrDoc = .FullName .Close End With Set Doc2 = Nothing Set Doc3 = Documents.Open(FileName:=Doc1.Path & "\Email Merge Main Document.doc", _ AddToRecentFiles:=False) With Doc3.MailMerge .MainDocumentType = wdEMail .OpenDataSource Name:=StrDoc, ConfirmConversions:=False, ReadOnly:=False, _ LinkToSource:=True, AddToRecentFiles:=False, Connection:="", SQLStatement:="", _ SQLStatement1:="", SubType:=wdMergeSubTypeOther If .State = wdMainAndDataSource Then '.Destination = wdSendToNewDocument .Destination = wdSendToEmail .MailAddressFieldName = "Outstanding Invoices" .MailSubject = "Monthly Sales Stats" .MailFormat = wdMailFormatHTML .Execute End If End With Doc3.Close SaveChanges:=False Set Doc3 = Nothing Application.ScreenUpdating = True End Sub Sub EmailMergeTableMaker(DocName As Document) Dim oTbl As Table, i As Integer, j As Integer, oRow As Row, oRng As Range, strTxt As String With DocName .Paragraphs(1).Range.Delete Call TableJoiner For Each oTbl In .Tables j = 2 With oTbl i = .Columns.Count - j For Each oRow In .Rows Set oRng = oRow.Cells(j).Range With oRng .MoveEnd Unit:=wdCell, Count:=i .Cells.Merge strTxt = Replace(.Text, vbCr, vbTab) On Error Resume Next If Len(strTxt) > 1 Then .Text = Left(strTxt, Len(strTxt) - 2) End With Next End With Next For Each oTbl In .Tables For i = 1 to j oTbl.Columns(i).Cells.Merge Next Next With .Tables(1) .Rows.Add BeforeRow:=.Rows(1) .Cell(1, 1).Range.Text = "Recipient" .Cell(1, 2).Range.Text = "Data" End With .Paragraphs(1).Range.Delete Call TableJoiner End With Set oRng = Nothing End Sub Private Sub TableJoiner() Dim oTbl As Table For Each oTbl In ActiveDocument.Tables With oTbl.Range.Next If .Information(wdWithInTable) = False Then .Delete End With Next End Sub Thanks! |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
heyullama | Excel | 7 | 12-01-2013 03:32 PM |
Mail Merge Many URLs in one email by common email address | instantaphex | Mail Merge | 3 | 04-29-2013 05:46 PM |
Mail Merge to email, changing images on email layout | ginelli | Mail Merge | 18 | 02-23-2013 09:47 AM |
![]() |
15Degrees | Mail Merge | 1 | 01-31-2013 02:06 AM |
Send e-mail message in Finish & Merge | CDTom | Mail Merge | 1 | 08-24-2012 12:52 AM |