VBA Connect to Data Source and Execute Mail Merge

rsmeyerson

Board Regular
Joined
Nov 29, 2014
Messages
104
I'm hoping to get some help completing a mail merge using VBA. I have already formatted a word document and added all merge fields from my data source which is an excel sheet named "PaymentDue". I have code that opens my word document, but it does not connect to my data source. When I open the word doc manually, I am prompted by a message box which states "Opening this document will run the following SQL command." By answering "Yes", the data source is connected to the word document. Can someone please help me connect my word document to my data source, and then execute a mail merge?

Here is the code I have which opens my word document:

Code:
Sub Run_Mail_Merge()


Dim wordApp As Object
    Set wordApp = CreateObject("Word.Application")
    wordApp.Documents.Open Filename:="C:\Users\bmeyerson\Desktop\FICO_Merge.docx"
    wordApp.Visible = True


End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Forum statistics

Threads
1,214,649
Messages
6,120,733
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top