JedStarkiller
New Member
- Joined
- Jun 19, 2017
- Messages
- 2
Hey Excel Guru's! I could use some help. I am trying to automate a process we have several letters we send out and I am trying to make it where we can just select the people and letter. I am just working on automating the mail merge feed from Excel. When I do the merge via Word manually it works fine. However when I try to run the following macro Word will crash if you try to click through the created pages, or if you try to select the edit recipients options. Is there something in the code causing this?
Code:
Sub OPENWORD()Dim Bottom As Long
Set appWd = CreateObject("Word.Application")
appWd.Visible = True
appWd.Documents.Open Filename:="C:\Term Project\Termed EE - Retirement Only Letter.docx"
appWd.ActiveDocument.MailMerge.MainDocumentType = wdFormLetters
appWd.ActiveDocument.MailMerge.OpenDataSource Name:= _
"C:\Term Project\2017 Termination Lists-DWH.xlsm", _
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:= _
"Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=C:\Term Project\2017 Termination Lists-DWH.xlsm;Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Engine Type=35;Jet OLE" _
, SQLStatement:="SELECT * FROM `'CURRENT TERM LIST$'` where `EE ID #` is not NULL", SQLStatement1:="" _
, SubType:=wdMergeSubTypeAccess
appWd.ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle
End Sub