MailMerge to Document Dialog Box

T

THE Burg

I have a number of documents (Word 2003) created using MailMerge (Excel as
data source). I've now been asked to automate a task that requires me to use
VBA with some event trapping and command reprogramming. Basically, I'm
trying to read something from a table within the document and put that value
into the header. I'm using VBA and a doc variable because the location of
the data within the document is somewhat of a moving target making
bookmarking difficult. (Note, as I think of it now, I could probably use the
VBA logic I use to find and read the data to set a bookmark around it then
use a REF in the header -- that'll be plan B, but I'm deep enough into this
that I want to see if the way I started will work.

The problem lies in the event trapping, not in the data collection and
placement sub. I set up DocumentBeforePrint, DocumentBeforeSave, and
MailMergeBeforeRecordMerge routines that simply call the data collection...
sub. This worked great for Save and for Merge to printer -- I think it
worked for direct print too although I can't remember testing. The problem
was with Merge to New Doc. When I did this, the new file would open and
become the active document before the data.... sub found it's data and the
whole thing would blow up big time! I think I tried MailMergeBeforeMerge
too, and I don't remember why, but it didn't work either.

OK, to get around this, I trashed the MailMergeBefore... and decided to
intercept the two MailMerge buttons we use. (Merge to New Doc & Merge to
Printer). I got this:

Sub MailMergeToDoc()
WordBasic.MailMergeToDoc
End Sub

to which I added the call to my data sub as:

Sub MailMergeToDoc()
Call ThisDocument.Rev_Level
WordBasic.MailMergeToDoc
End Sub

The update worked, but the merge to document dialog box wasn't displayed so
it usually just merges all records. (I think it actually goes to a default
value because I did see a case where it just merged one record, probably the
record requested the last time I used the function.)

I can change to VBA equivalents and add

Dialogs(wdDialogMailMerge).Show

and get a dialog box that allows me to do what I want, but it's a more
robust dialog box than what I normally get and I'm sure it will confuse my
user. I just want the dialog box that we normally get when we click the
Merge to New Document button, the one that gives three radio buttons: All,
Current, and FROM ____ TO ____.

Is this possible?
 
C

Cindy M.

Hi =?Utf-8?B?VEhFIEJ1cmc=?=,
The update worked, but the merge to document dialog box wasn't displayed so
it usually just merges all records. (I think it actually goes to a default
value because I did see a case where it just merged one record, probably the
record requested the last time I used the function.)

I can change to VBA equivalents and add

Dialogs(wdDialogMailMerge).Show

and get a dialog box that allows me to do what I want, but it's a more
robust dialog box than what I normally get and I'm sure it will confuse my
user. I just want the dialog box that we normally get when we click the
Merge to New Document button, the one that gives three radio buttons: All,
Current, and FROM ____ TO ____.

Is this possible?
Try this

'Executes the merge
commandBars.ExecuteMso "MailMergeMergeToDocument"

or

'only shows the dialog box
commandBars.ExecuteMso "MailMergeMergeToNewDocumentOptions"

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
T

THE Burg

Hi Cindy,

I tried the second method:
CommandBars.ExecuteMso "MailMergeMergeToNewDocumentOptions"
and got:
Compile Error:
Method or data member not found (ExecuteMso highlighted)

Tried looking through the command bars topics in help but didn't figure
anything out.

Please let me know if you know of anything else I can try or anything I did
wrong.

Thanks.

Paul
 
M

Marcel

Paul,

I had similar problems and recordered some vba and got in a bigger part the
next code snippet. Here you see that you can supply a first record and a last
record. I would assume that you can create a form of your own and get the two
values for the fisrt and last record.

..
..
'<put here your form with two properties, first and last>
..
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = MyForm1.first
.LastRecord = MyForm1.last
End With
.Execute Pause:=False
End With
..
..

Regards,

Marcel
 

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