Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
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
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
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
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
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
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
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 | |
|
|
Similar Threads | ||||
Thread | Forum | |||
set up a list of events and dates In WORD | Microsoft Word Help | |||
Days on a calendar as watermark/background so events can be overto | Microsoft Word Help | |||
Keyboard input handling events | New Users | |||
Mail Merge events and VB.NET | Mailmerge | |||
Mail Merge Events | Mailmerge |