ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel/Word Mail Merge Problem (https://www.excelbanter.com/excel-programming/277534-excel-word-mail-merge-problem.html)

AA[_2_]

Excel/Word Mail Merge Problem
 
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 the
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



-----Original Message-----
Can anybody help me with a mail merge problem please?



What we do now

When we have a product recall at work, we can run a

report from our Sales
Order system, which outputs to a comma-separated text

file, a list of
customers together with the Batch Number, Order Number,

Description, Date
etc. of their order.



We import the text file into Microsoft Excel and use it

as a mail merge
list. The relevant fields are inserted into a Microsoft

Word mail-merge
document, printed and sent to the customer.



The Problem

Some customers may have several orders of the same

recalled product, often
more than ten. If a customer has more than one order for

the product, then
they get a letter for each order e.g. 10 orders = 10

letters telling them
same thing. The only thing that changes is the order

number and date. The
customer details, product description and batch number

stay the same.



Required Solution

Is there any way to have the mail merge print one letter

per customer and
simply list the Order Numbers and Purchase Dates within

the same letter?



Office Version

Office XP



I would appreciate any help on this, even to point me in

the right
direction. My guess is that you somehow read the

contents of the
spreadsheet cells into resizable arrays and somehow print

the contents into
the mail merge Word document, adding a new line to the

word document for
each Order Number found for a particular customer, and

then move on to the
next letter/customer.



Perhaps this can all be done within Excel?



The trouble is my VBA isn't that good.



Please send any help to



Thanks in advance for any help you can give me.



P.S. I have sent this email to a few word/excel groups

since it involves
both progames - I hope this is all right.




.



All times are GMT +1. The time now is 11:40 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com