Hi all
Been struggling a bit with a piece of code to try get my Word Doc to mail merge with data from my spreadsheet. Says it's having an issue with the last line i.e. "SQLStatement:="SELECT*FROM[Sheet2$]"
Assistance would be greatly appreciated - still new to working with this.
Been struggling a bit with a piece of code to try get my Word Doc to mail merge with data from my spreadsheet. Says it's having an issue with the last line i.e. "SQLStatement:="SELECT*FROM[Sheet2$]"
Assistance would be greatly appreciated - still new to working with this.
VBA Code:
Sub Open_Word_Document()
'On Error Resume Next
'Opens a Word Document from Excel
Dim objWord As Object
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
'Change the directory path and file name to the location
'of your document
objWord.Documents.Open "C:\Users\gavin\Desktop\funding\funding.docx"
With objWord
.ActiveDocument.MailMerge.OpenDataSource Name:="C:\users\gavin\desktop\funding\funding_Summary.xlsm" _
, ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:="", _
SQLStatement:="SELECT*FROM[Sheet2$]"
With .ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
End With
'
End Sub