Macro not recording mailmerge

L

LDanix

I am using Word 2003. I am trying to get a macro to record the following
commands:
Open Data Source
Mail Merge Recipients
Merge to New Document

The first and last commands are recorded. But the Mail Merge Recipients part
of my actions is not recorded.
Is this normal? How can I fix or get around it?

Thanks
 
P

Peter Jamieson

It's normal. Lots of things don't record.

In this case you can probably do

Dialogs(wdDialogMailMergeRecipients).Display


Generally speaking if you are using Dialog boxes and need to access any
fields they may have exposed, you need to do something more like the
following but I do not think it is necessary in this case:

Dim dlgMailMergeMRecipients As Dialog
Set dlgMailMergeMRecipients = Dialogs(wdDialogMailMergeRecipients)
dlgMailMergeMRecipients.Display
Set dlgMailMergeMRecipients = Nothing

Peter Jamieson
 
L

LDanix

"Dialogs(wdDialogMailMergeRecipients).Display" worked to get the box to
display. Now I need it to do a few things there before closing and executing
the merge. If its possible, would you mind helping me with the code? If you
don't, here's what I need:

1. Clear All
2. Filter column "CurrentStatus" to only display "Active"
3. Select All
4. Close Dialog Box

After the merge has executed, I would like to have it close the original
document and keep the newly created document open.

Thanks in advance
 
P

Peter Jamieson

OK, as far as I know you cannot mainpulate this particular dialog box to
that level. Some Dialog boxes in Word are more programmable than others.

The way to achieve this particular result is to generate the SQL query you
need to get the correct data, and either
a. issue it in an OpenDataSource call or
b. use it to set ActiveDcocument.Mailmerge.Datasource.Querystring

(generally speaking, (b) sometimes works, and (a) should always work as long
as the data source is disconnected before you start).

The precise query depends on which type of data source you are using
(different dialects of SQL are used, and the way that the "table" is named
in the SQL can vary), but if you apply the criteria you want manually, then
use the Immediate window in VBE to print the value of

ActiveDocument.Mailmerge.Datasource.Querystring

you should see what is required for (b). It will be something like

SELECT * FROM mytable WHERE CurrentStatus = 'Active'

See where that leads you - if you need more on OpenDataSource, I have posted
many examples in this group so searching for Jamieson OpenDataSource on
Google Groups may help.

Peter Jamieson
 

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