PDA

View Full Version : Excel Database + Word MailMerge



smallxyz
01-07-2017, 01:35 AM
I have a Excel database with records, and a Word file with a customized template.
Upon the opening of the Word file, the Excel data are required to connect to the Word and execute mail merge.


The code below works well and is inserted into the Word 's Module.


' [ Doc_Open ]
Private Sub Document_Open()
'------------------------------
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
'------------------------------
End Sub


However, it always prompts the user to select the Excel path during start.​
As the path of that Excel file is always fixed, how to amend code such that, during the next file opening, no path selection is required?

Thanks !

macropod
01-07-2017, 04:38 AM
Cross-posted (and answered) at: http://www.mrexcel.com/forum/general-excel-discussion-other-questions/984257-excel-database-word-mailmerge.html
Please read our policy on Cross-Posting in item3 of the board rules: http://www.vbaexpress.com/forum/faq.php?faq=new_faq_item#faq_new_faq_item3