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?
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?