Excel/Word Mail Merge Problem

A

AA

You need to select the distinct customers from the csv
file before doing the main merge. This code should get you
most of the way there:
The [ ] and comment lines are where you need to make
changes- replace the [] too. I assumed that your CSV file
has column names.

Sub xx()

Cnn="Provider=MSDASQL;Driver={Microsoft Text Driver
(*.txt; *.csv)};DBQ=c:\[YOUR LOCATION];"
Sql="Select distinct(customer)[ add other columns
separated by ,] from [YOUR FILE NAME]"
Set ADORS=CreateObject("ADODB.Recordset")
ADORS.Open Sql,Cnn
' Open a text file here with handle FileHwnd

While NOT ADORS.EOF
print FileHwnd,ADORS.GetString
wend

'Close file here (its tab delimited)
'Read in Excel & save as csv under a new name as xls.

Mailmerger with existing Word setup & new excel file
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top