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