Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Andrew Kennard[_2_] Andrew Kennard[_2_] is offline
external usenet poster
 
Posts: 19
Default Mailmerge & Print events

Hi all

I would like to be able to automate a mail merge of records/documents one by
one so that I can get notifications of things happening

I see in the Word 2003 Object model there are events for MailMergeAfterMerge
and DocumentBeforePrint

I don't want the whole process to be too slow but I really need to kepp
tight control on which merged documents have/havn't been printed.

There does not seem to be an "DocumentAfterPrint" event ? I assume this is
because I suppose you can't tell when a document is "actually" printed with
buffers/network printers etc etc

Does anyone have a "one merge document at a time" example to give me a head
start ?

When you start to do merges from larger source data say 10,000+ records you
really need tight control incase of jams etc etc to make it easier to
restart and keep track of things etc

Thanks in advance for any advise

Kind Regards

Andrew






  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Mailmerge & Print events

There does not seem to be an "DocumentAfterPrint" event ? I assume this is
because I suppose you can't tell when a document is "actually" printed
with buffers/network printers etc etc


I don't know, but that would be my guess too (NB, the people here are mainly
volunteers who don't work for Microsoft, so you are unlikely to get
definitive information on why things were designed a particular way).

You can use a macro like the following to perform the merge, but only if
your mail merge main document does not have any Next record fields and
similar stuff such as Next record if . NB, the loop is more complicated
than a simple for...next simply because I have found that the record numbers
are not necessarily what you might expect in some cases.

Peter Jamieson

Sub ProduceOneDocPerSourceRec()
'

' NB, needs bettor error management and doubtless other things a VBA expert
' will point out.

Dim intSourceRecord
Dim objMerge As Word.MailMerge
Dim strEman As String
Dim strOutputDocumentName As String
Dim TerminateMerge As Boolean

' Need to set up this object as the ActiveDocument changes when the
' merge is performed. Besides, it's clearer.

Set objMerge = ActiveDocument.MailMerge
With objMerge

' If no data source has been defined, do it here using OpenDataSource.
' But if it is already defined in the document, you should not need to
define it here.

' .OpenDataSource _
' Name:="whatever"

intSourceRecord = 1
TerminateMerge = False

Do Until TerminateMerge
.DataSource.ActiveRecord = intSourceRecord

' if we have gone past the end (and possibly, if there are no records)
' then the Activerecord will not be what we have just tried to set it to

If .DataSource.ActiveRecord intSourceRecord Then
TerminateMerge = True
' the record exists
Else

' while we are looking at the correct activerecord,
' create the document path name
' e.g. - you will need to change this -
strEman = StrReverse(objMerge.Name)
StrReverse(Mid(strEman, InStr(1, strEman & ".", ".") + 1))

strOutputDocumentName = _
"c:\mydoc\" & _
StrReverse(Mid(strEman, InStr(1, strEman & ".", ".") + 1)) & _
.DataSource.Datafields("CaseID").Value & ".doc"

.DataSource.FirstRecord = intSourceRecord
.DataSource.LastRecord = intSourceRecord
.Destination = wdSendToNewDocument
.Execute

' The Activedocument is always the output document
' Add any parameters you need to these calls
ActiveDocument.SaveAs strOutputDocumentName
ActiveDocument.Close
intSourceRecord = intSourceRecord + 1
End If
Loop
End With
End Sub


"Andrew Kennard" wrote in message
...
Hi all

I would like to be able to automate a mail merge of records/documents one
by one so that I can get notifications of things happening

I see in the Word 2003 Object model there are events for
MailMergeAfterMerge and DocumentBeforePrint

I don't want the whole process to be too slow but I really need to kepp
tight control on which merged documents have/havn't been printed.

There does not seem to be an "DocumentAfterPrint" event ? I assume this is
because I suppose you can't tell when a document is "actually" printed
with buffers/network printers etc etc

Does anyone have a "one merge document at a time" example to give me a
head start ?

When you start to do merges from larger source data say 10,000+ records
you really need tight control incase of jams etc etc to make it easier to
restart and keep track of things etc

Thanks in advance for any advise

Kind Regards

Andrew








  #3   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Andrew Kennard[_2_] Andrew Kennard[_2_] is offline
external usenet poster
 
Posts: 19
Default Mailmerge & Print events

Peter

Thanks very much for your detailed reply and example which is very useful.

Could you expand on "NB, the loop is more complicated than a simple
for...next simply because I have found that the record numbers are not
necessarily what you might expect in some cases." ?

Your loop seems to terminate when an unexpected record is found. Is it just
that when you 'fall off the end' the contents of the 'next record' can be
unpredictable ?

A 2nd question. I'm surprised how few events Word has for helping with
automation. One other thing I need to do is get the name of the document
that has just been saved by the user in a SaveAs ie they typed it in so I
don't know what it is. I'm currently looking at the WindowDeactivate event
as this seems to fire pretty late in the order of things. Have you done
anything similar ? to get the Document.Name and Document.Path back into your
application so that you can do something with it. ?

Thanks again

Andrew


"Peter Jamieson" wrote in message
...
There does not seem to be an "DocumentAfterPrint" event ? I assume this
is because I suppose you can't tell when a document is "actually" printed
with buffers/network printers etc etc


I don't know, but that would be my guess too (NB, the people here are
mainly volunteers who don't work for Microsoft, so you are unlikely to get
definitive information on why things were designed a particular way).

You can use a macro like the following to perform the merge, but only if
your mail merge main document does not have any Next record fields and
similar stuff such as Next record if . NB, the loop is more
complicated than a simple for...next simply because I have found that the
record numbers are not necessarily what you might expect in some cases.

Peter Jamieson

Sub ProduceOneDocPerSourceRec()
'

' NB, needs bettor error management and doubtless other things a VBA
expert
' will point out.

Dim intSourceRecord
Dim objMerge As Word.MailMerge
Dim strEman As String
Dim strOutputDocumentName As String
Dim TerminateMerge As Boolean

' Need to set up this object as the ActiveDocument changes when the
' merge is performed. Besides, it's clearer.

Set objMerge = ActiveDocument.MailMerge
With objMerge

' If no data source has been defined, do it here using OpenDataSource.
' But if it is already defined in the document, you should not need to
define it here.

' .OpenDataSource _
' Name:="whatever"

intSourceRecord = 1
TerminateMerge = False

Do Until TerminateMerge
.DataSource.ActiveRecord = intSourceRecord

' if we have gone past the end (and possibly, if there are no records)
' then the Activerecord will not be what we have just tried to set it
to

If .DataSource.ActiveRecord intSourceRecord Then
TerminateMerge = True
' the record exists
Else

' while we are looking at the correct activerecord,
' create the document path name
' e.g. - you will need to change this -
strEman = StrReverse(objMerge.Name)
StrReverse(Mid(strEman, InStr(1, strEman & ".", ".") + 1))

strOutputDocumentName = _
"c:\mydoc\" & _
StrReverse(Mid(strEman, InStr(1, strEman & ".", ".") + 1)) & _
.DataSource.Datafields("CaseID").Value & ".doc"

.DataSource.FirstRecord = intSourceRecord
.DataSource.LastRecord = intSourceRecord
.Destination = wdSendToNewDocument
.Execute

' The Activedocument is always the output document
' Add any parameters you need to these calls
ActiveDocument.SaveAs strOutputDocumentName
ActiveDocument.Close
intSourceRecord = intSourceRecord + 1
End If
Loop
End With
End Sub


"Andrew Kennard" wrote in message
...
Hi all

I would like to be able to automate a mail merge of records/documents one
by one so that I can get notifications of things happening

I see in the Word 2003 Object model there are events for
MailMergeAfterMerge and DocumentBeforePrint

I don't want the whole process to be too slow but I really need to kepp
tight control on which merged documents have/havn't been printed.

There does not seem to be an "DocumentAfterPrint" event ? I assume this
is because I suppose you can't tell when a document is "actually" printed
with buffers/network printers etc etc

Does anyone have a "one merge document at a time" example to give me a
head start ?

When you start to do merges from larger source data say 10,000+ records
you really need tight control incase of jams etc etc to make it easier to
restart and keep track of things etc

Thanks in advance for any advise

Kind Regards

Andrew










  #4   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Mailmerge & Print events

To be honest, I can't reemember, as it's a long time since I wrote this, but
I think it was actually to do with one or both of the folowing
a. Lastrecord not always being filled in correctly, so you can't just do
For myrec = 1 to .Lastrecord
b. user selections creating gaps in the record sequence that aren'y
actually reflected in the value of Lastrecord.

A 2nd question. I'm surprised how few events Word has for helping with
automation. One other thing I need to do is get the name of the document
that has just been saved by the user in a SaveAs ie they typed it in so I
don't know what it is.


You probably need to use the built-in SaveAs dialog - see for example
http://word.mvps.org/FAQs/MacrosVBA/...SaveAsPath.htm

Peter Jamieson

"Andrew Kennard" wrote in message
...
Peter

Thanks very much for your detailed reply and example which is very useful.

Could you expand on "NB, the loop is more complicated than a simple
for...next simply because I have found that the record numbers are not
necessarily what you might expect in some cases." ?

Your loop seems to terminate when an unexpected record is found. Is it
just that when you 'fall off the end' the contents of the 'next record'
can be unpredictable ?

A 2nd question. I'm surprised how few events Word has for helping with
automation. One other thing I need to do is get the name of the document
that has just been saved by the user in a SaveAs ie they typed it in so I
don't know what it is. I'm currently looking at the WindowDeactivate event
as this seems to fire pretty late in the order of things. Have you done
anything similar ? to get the Document.Name and Document.Path back into
your application so that you can do something with it. ?

Thanks again

Andrew


"Peter Jamieson" wrote in message
...
There does not seem to be an "DocumentAfterPrint" event ? I assume this
is because I suppose you can't tell when a document is "actually"
printed with buffers/network printers etc etc


I don't know, but that would be my guess too (NB, the people here are
mainly volunteers who don't work for Microsoft, so you are unlikely to
get definitive information on why things were designed a particular way).

You can use a macro like the following to perform the merge, but only if
your mail merge main document does not have any Next record fields
and
similar stuff such as Next record if . NB, the loop is more
complicated than a simple for...next simply because I have found that the
record numbers are not necessarily what you might expect in some cases.

Peter Jamieson

Sub ProduceOneDocPerSourceRec()
'

' NB, needs bettor error management and doubtless other things a VBA
expert
' will point out.

Dim intSourceRecord
Dim objMerge As Word.MailMerge
Dim strEman As String
Dim strOutputDocumentName As String
Dim TerminateMerge As Boolean

' Need to set up this object as the ActiveDocument changes when the
' merge is performed. Besides, it's clearer.

Set objMerge = ActiveDocument.MailMerge
With objMerge

' If no data source has been defined, do it here using OpenDataSource.
' But if it is already defined in the document, you should not need to
define it here.

' .OpenDataSource _
' Name:="whatever"

intSourceRecord = 1
TerminateMerge = False

Do Until TerminateMerge
.DataSource.ActiveRecord = intSourceRecord

' if we have gone past the end (and possibly, if there are no records)
' then the Activerecord will not be what we have just tried to set it
to

If .DataSource.ActiveRecord intSourceRecord Then
TerminateMerge = True
' the record exists
Else

' while we are looking at the correct activerecord,
' create the document path name
' e.g. - you will need to change this -
strEman = StrReverse(objMerge.Name)
StrReverse(Mid(strEman, InStr(1, strEman & ".", ".") + 1))

strOutputDocumentName = _
"c:\mydoc\" & _
StrReverse(Mid(strEman, InStr(1, strEman & ".", ".") + 1)) & _
.DataSource.Datafields("CaseID").Value & ".doc"

.DataSource.FirstRecord = intSourceRecord
.DataSource.LastRecord = intSourceRecord
.Destination = wdSendToNewDocument
.Execute

' The Activedocument is always the output document
' Add any parameters you need to these calls
ActiveDocument.SaveAs strOutputDocumentName
ActiveDocument.Close
intSourceRecord = intSourceRecord + 1
End If
Loop
End With
End Sub


"Andrew Kennard" wrote in message
...
Hi all

I would like to be able to automate a mail merge of records/documents
one by one so that I can get notifications of things happening

I see in the Word 2003 Object model there are events for
MailMergeAfterMerge and DocumentBeforePrint

I don't want the whole process to be too slow but I really need to kepp
tight control on which merged documents have/havn't been printed.

There does not seem to be an "DocumentAfterPrint" event ? I assume this
is because I suppose you can't tell when a document is "actually"
printed with buffers/network printers etc etc

Does anyone have a "one merge document at a time" example to give me a
head start ?

When you start to do merges from larger source data say 10,000+ records
you really need tight control incase of jams etc etc to make it easier
to restart and keep track of things etc

Thanks in advance for any advise

Kind Regards

Andrew











Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
set up a list of events and dates In WORD PAMMYSTUDENT Microsoft Word Help 1 June 23rd 06 03:56 PM
Days on a calendar as watermark/background so events can be overto Scott@Regions Microsoft Word Help 1 March 21st 06 08:07 PM
Keyboard input handling events Shan New Users 0 September 23rd 05 07:16 AM
Mail Merge events and VB.NET Bill S. Mailmerge 1 August 12th 05 08:48 PM
Mail Merge Events Bill S. Mailmerge 1 March 10th 05 12:33 PM


All times are GMT +1. The time now is 12:20 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"