locked
Mail-Merge to E-mail with Subject personalised by Mail-Merge Fields. RRS feed

  • Question

  • Mail-Merge to E-mail with Subject personalised by Mail-merge Fields

    I know this is impossible, but it can be approximated.  The attached code enables you to put character strings like “<<Addressee>>”, rather than real Mail-Merge Fields, in the Subject of a WORD Mail-Merge to E-mail.  The routines in the code then change the Subject for each E-mail sent, so that the contents of the column ‘Addressee’ in the Mail-Merge Data Source are substituted for the “<<Addressee>>”. 

    There is however a severe limitation on its usefulness.  The Document has to be saved and re-opened after the code has been added to the Document for it to work.  This is because the Document_Open routine has to initialise the m_WORDapplication Object that controls the Merge. 

    Background

    For many years we have had an application that creates Excel Mail-Merge Data Sources from data held in an SQL Server Database.  The application then draws on a library of WORD Templates changing MacroButtons in the Template into values from the Database.  If the E-mail is going to multiple recipients the appropriate Mail-Merge Data Source is attached.  Otherwise the Mail-Merge Fields are substituted by the application – thus avoiding the need for a mail-merge. 

    The Document is then opened in WORD.  The user is then left to make any further changes and either send the E-mail or complete the Mail-Merge as normal.  Any changes the User makes are captured when the Document closes.  The first 255 characters of the Document Body are stored and cross-indexed in the SQL Server Database.  The original document is stored in a Windows Folder structure, from where it can be retrieved when needed. 

    What we now wish to do

    So far our application populates the E-mail Envelope with the Subject.  However when the User does a Merge to E-mail, the Subject is not transferred to the ‘Merge to E-mail’ Dialog.  We would like to find a way of doing so.  This is not essential as the User can always copy and paste, but it’s a little inelegant. 

    When the User clicks OK in this Dialog we then want the WORD Mail-Merge to personalise the Subject line of each E-mail with Fields from the Mail-Merge Data Source – without the need to close and re-open the document. 

    Progress to Date

    So far we have developed the code that actually does the Merge.  However it has to be in the Word Document.  Can we insert it there from the Access VBA or does it have to be built into the templates to start with?  If so how, exactly? 

    We have tried adding it to the WORD Template, but it does not run – even if we save the document as a .docm re-open it and enable the Marcos.  Even if I copy the VBA for the Project Template into the WORD Document, re-save and re-open it still does not run.  I have no idea why not. 

    We also have to find some other way of initialising the m_WORDapplication Object, other than in the Document_Open routine.  This is because as soon as the WORD Document closes our application thinks the User has finished with the Document and sets about filing it. 

    Existing Code

    'Acknowledgment:
    '---------------
    '   This code is a modified version of that found at:
    '       http://www.access-programmers.co.uk/forums/showthread.php?t = 153216
    '
    '   However it has been modified to:
    '
    '       - confirm to our own variable naming and documentation standards,
    '
    '       - All subs have been wrapped with:
    '               If ActiveDocument.MailMerge.Destination = wdSendToEmail Then
    '               ......
    '               End If
    '         To avoid Errors if user merges to Printer.
    '
    '       - We have changed the replacement delimiters in the .MailSubject from:
    '               <.....>
    '         to
    '               <<.....>>
    '         as this more nearly represents standard MailMerge Field.
    '
    '       - We explicitly count Mail-Merge DataSource Fields in Document
    '               i_NumberOfMergeFields = .DataSource.DataFields.Count
    '         and then use a For...Next loop:
    '               For i = 1 To i_NumberOfMergeFields
    '               .....
    '               Next i
    '         to control the scanning of:
    '               ActiveDocument.MailMerge.DataSource.DataFields(i)
    '         as, in our Application, the most likely candidates for substitution are early on,
    '         with lower values of i.
    '
    '       - Included an exit from the For...Next loop to save processing.
    '               'If there are no Merge-Fields left in .MailSubject Exit For loop
    '               If InStr(1, .MailSubject, "<<") = 0 Then Exit For


    'Declaration of Module Level Variables, which are available throughout this Module
    '=================================================================================
        Dim WithEvents m_WORDapplication As Application
       
        Dim m_b_WORDapplication_AlreadyOpen As Boolean

        Dim m_s_EmailSubject As String
        Dim m_b_FirstRecord As Boolean


    Private Sub Document_Open()
        Set m_WORDapplication = Application
        m_b_WORDapplication_AlreadyOpen = True
        ThisDocument.MailMerge.ShowWizard 6
    End Sub


    Private Sub m_WORDapplication_MailMergeBeforeMerge(ByVal Doc As Document, ByVal StartRecord As Long, ByVal EndRecord As Long, Cancel As Boolean)
       
        If ActiveDocument.MailMerge.Destination = wdSendToEmail Thenthe
            'Initialise the Module level variable m_b_FirstRecord
            'so that Sub m_WORDapplication_MailMergeBeforeRecordMerge will know it 's dealing with the FirstRecord
            m_b_FirstRecord = True
        End If
       
    End Sub


    Private Sub m_WORDapplication_MailMergeBeforeRecordMerge(ByVal Doc As Document, Cancel As Boolean)
    '
    '   Written by: Brian McGuigan
    '           of: On2it Software Ltd
    '      Version: 1
    '        Dated: 26-Mar-14
    'First Used in: NEXT Version
    '       Status: Tested
    '
    '      Purpose: This Subroutine changes the ActiveDocument.MailMerge.MailSubject before each Record is merged.
    '
    '       Method: It does so by replacing any
    '                   ActiveDocument.MailMerge.DataSource.DataFields(i).Name
    '               it finds in the
    '                   .MailSubject
    '               delimited by <<.....>> with the corresponding
    '                   .DataSource.DataFields(i).Value

        Dim i_NumberOfMergeFields As Integer
        Dim i As Integer
       
        With ActiveDocument.MailMerge
           
            If .Destination = wdSendToEmail Then
       
                If m_b_FirstRecord = True Then
                    'Remember .MailSubject complete with Mail-Merge Fields as originally entered with <<.....>>
                    m_s_EmailSubject = .MailSubject
                    m_b_FirstRecord = False
                Else
                    'Reset .MailSubject to so that it still contains the Mail-Merge Fields as entered with <<.....>>
                    .MailSubject = m_s_EmailSubject
                End If
       
                'Count Mail-Merge DataSource Fields in Document
                i_NumberOfMergeFields = .DataSource.DataFields.Count
               
                'Replace each Mail-Merge DataSource Field delimited with <<.....>> in .MailSubject
                For i = 1 To i_NumberOfMergeFields
                   
                    .MailSubject = Replace( _
                        Expression:=.MailSubject, _
                        Find:="<<" & .DataSource.DataFields(i).Name & ">>", _
                        Replace:=.DataSource.DataFields(i).Value, _
                        Compare:=vbTextCompare)
               
                    'If there are no Merge-Fields left in .MailSubject Exit For loop
                    If InStr(1, .MailSubject, "<<") = 0 Then Exit For
                   
                Next i
               
                m_b_FirstRecord = False
           
            End If
           
        End With
       
    End Sub


    Private Sub m_WORDapplication_MailMergeAfterMerge(ByVal Doc As Document, ByVal DocResult As Document)
        ActiveDocument.MailMerge.MailSubject = m_s_EmailSubject
    End Sub


    Private Sub Document_Close()
        If ActiveDocument.MailMerge.Destination = wdSendToEmail Then
            Set m_WORDapplication = Nothing
        End If
    End Sub

    Friday, October 17, 2014 12:42 AM

Answers

  • The problem with inserting code dynamically is that the Word user has to have allowed programmatic access to the VBA project object model (via the Options->Trust Center->Trust Center Settins...->Macro settings in (say) Word 2013). If you can ensure that your users have that set, you are probably OK.

    Otherwise, I just wonder whether the following suggestions may get you started on an approach that does put code in a .dotm (all the mail merge main document would need to be attached to that .dotm - otherwise, you can consider a template used as an Addin, but that introduces a different set of condierations).

    Assuming that Word is not detaching the data source if/when you open the Word document from your Access code (assuming that is what you are doing), then the mailmerge data source should already be attached, and you your application ought to be able to write the .Mailmerge.MailSubject and .MailAddress properties of the document. Otherwise, if the user has to manually re-attach the data source, it's not so obvious at what point the MailSubject (say) could be specified - in the Before Merge event is too late, I think.

    Anyway, the following changes made the .dotm approach worked for me, in the sense that the appropriate events fired. Even if this code structure works for you, you will probably need to do more, e.g. if you want to avoid problems if the user has two of these documents open at the same time. 

    In your .dotm's ThisDocument module, put

    Dim app As appEventClass
    Private Sub Document_Open()
    MsgBox "In mmeventcode1 document_open"
    Set app = New appEventClass
    Set app.m_WORDapplication = Word.Application
    ' You may need to track this differently now...
    app.m_b_WORDapplication_AlreadyOpen = True
    ' So this should show the Wizard in the document the user has just opened...
    ActiveDocument.MailMerge.ShowWizard 6
    End Sub

    Private Sub Document_Close()
    MsgBox "In mmeventcode1 document_close"
    If ActiveDocument.MailMerge.Destination = wdSendToEmail Then
      Set app.m_WORDapplication = Nothing
      Set app = Nothing
    End If
    End Sub

    Then in a CLass module called appEventClass, put the rest of your code, slightly modified. Not *that* important, but notice that I have used the Doc parameter passed to the routines rather than the ActiveDocument reference. 

        Public WithEvents m_WORDapplication As Application

        Public m_b_WORDapplication_AlreadyOpen As Boolean

        Dim m_s_EmailSubject As String
        Dim m_b_FirstRecord As Boolean

    Private Sub m_WORDapplication_MailMergeBeforeMerge(ByVal Doc As Document, ByVal StartRecord As Long, ByVal EndRecord As Long, Cancel As Boolean)
    MsgBox "In mmeventcode1 MMBM"

        If Doc.MailMerge.Destination = wdSendToEmail Then
            'Initialise the Module level variable m_b_FirstRecord
            'so that Sub m_WORDapplication_MailMergeBeforeRecordMerge will know it's dealing with the FirstRecord
            m_b_FirstRecord = True
        End If

    End Sub


    Private Sub m_WORDapplication_MailMergeBeforeRecordMerge(ByVal Doc As Document, Cancel As Boolean)
    '
    '   Written by: Brian McGuigan
    '           of: On2it Software Ltd
    '      Version: 1
    '        Dated: 26-Mar-14
    'First Used in: NEXT Version
    '       Status: Tested
    '
    '      Purpose: This Subroutine changes the ActiveDocument.MailMerge.MailSubject before each Record is merged.
    '
    '       Method: It does so by replacing any
    '                   ActiveDocument.MailMerge.DataSource.DataFields(i).Name
    '               it finds in the
    '                   .MailSubject
    '               delimited by <<.....>> with the corresponding
    '                   .DataSource.DataFields(i).Value

        Dim i_NumberOfMergeFields As Integer
        Dim i As Integer
    MsgBox "In mmeventcode1 MMBRM"

        With Doc.MailMerge

            If .Destination = wdSendToEmail Then

                If m_b_FirstRecord = True Then
                    'Remember .MailSubject complete with Mail-Merge Fields as originally entered with <<.....>>
                    m_s_EmailSubject = .MailSubject
                    m_b_FirstRecord = False
                Else
                    'Reset .MailSubject to so that it still contains the Mail-Merge Fields as entered with <<.....>>
                    .MailSubject = m_s_EmailSubject
                End If

                'Count Mail-Merge DataSource Fields in Document
                i_NumberOfMergeFields = .DataSource.DataFields.Count

                'Replace each Mail-Merge DataSource Field delimited with <<.....>> in .MailSubject
                For i = 1 To i_NumberOfMergeFields

                    .MailSubject = Replace( _
                        Expression:=.MailSubject, _
                        Find:="<<" & .DataSource.DataFields(i).Name & ">>", _
                        Replace:=.DataSource.DataFields(i).Value, _
                        Compare:=vbTextCompare)

                    'If there are no Merge-Fields left in .MailSubject Exit For loop
                    If InStr(1, .MailSubject, "<<") = 0 Then Exit For

                Next i

                m_b_FirstRecord = False

            End If

        End With

    End Sub


    Private Sub m_WORDapplication_MailMergeAfterMerge(ByVal Doc As Document, ByVal DocResult As Document)
    MsgBox "In mmeventcode1 MMAM"
        If Doc.MailMerge.Destination = wdSendToEmail Then
          Doc.MailMerge.MailSubject = m_s_EmailSubject
        End If
    End Sub

                                                                                                                            

    Peter Jamieson

    Friday, November 28, 2014 3:49 PM

All replies

  • Hi,

    >>So far we have developed the code that actually does the Merge.  However it has to be in the Word Document.  Can we insert it there from the Access VBA or does it have to be built into the templates to start with?  If so how, exactly?    <<

    Yes, we can move the code to Access VBA. And based on the code you are binding event in Word application, to move the code into Access VBA, we need to bind the event our self.

    For example, we can create a class module like below to subscribe document open event:

    Class1:

    Option Compare Database
    
    Public WithEvents wordApp As Word.Application
    
    
    Private Sub wordApp_DocumentOpen(ByVal Doc As Word.Document)
     MsgBox "document open"
    End Sub
    
    

    Create a Module in Access VBA to open the document:

    Sub main()
    Dim Word As New Word.Application
    Dim myClass As New Class2
    Set myClass.wordApp = Word
    
    Word.Visible = True
    Word.Documents.Open ("C:\Users\UserName\Desktop\a.docx")
    End Sub
    

    Hope it is helpful.

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, October 17, 2014 9:13 AM
  • I'll try this out shortly and post results when tested.
    Tuesday, October 28, 2014 10:43 PM
  • I'm sorry.  I've only just had chance to look at your suggested code.  It appears to simply open a named Word Document from Access.

    This we are already doing.  We then substitute Mail-Merge fields and Macrobuttons to personalise the Document according to who it's going to and the member of staff that's sending it.  If it's going to multiple people we also attach a Mail-Merge Data Source generated from our application and leave the user to correct any spelling errors before sending the E-mail or completing the Mail-Merge. 

    We then capture the text that was actually sent, strip off any header and salutation and store the first 255 characters in an SQL Server Database, where it is cross-indexed by everyone it went to, and all of their organisations.  The original document is then filed with a meaningful name by subject in an ordinary Windows folder.  We can even create Shortcuts to it from Windows folders for any the other Organisations and People involved and create OUTLOOK follow-up Task.  So we're pretty used to being able to manipulate a WORD Document from Access. :-)

    This gives us the ability to use any WORD Document as a standard template for everyone in an organisation for both individual E-mails and Mail-Merged Documents.  At present there is no need for these original 'Templates' to have any VBA code in them at all.  All they need is the appropriate Mail-Merge fields and Macrobuttons, which will cause our code to substitute them correctly.

    We would LIKE this to continue to be the case.  However the code that I originally posted has to run during the Mail-Merge from inside WORD itself.  It HAS to because at that point in time the User is in control of WORD - not our Access VBA Code.  It is simply waiting for the WORD Document to close before it continues execution.  (We are aware that we can do this more elegantly if we use early binding to bind to specific version of WORD.  However we HAVE to use late binding so that our Users can use ANY version of WORD they like.)

    What we NOW want to be able to do, may well be impossible.  What we want to be able to do, is insert VBA code from Access into a WORD Document so that when WORD itself performs a Mail-Merge the inserted code executes from within WORD. 

    If we HAVE to we can always add the code into the WORD Template.  The question is - DO WE HAVE TO?

    Wednesday, November 26, 2014 10:08 PM
  • Hi Brain,

    Thanks for the detail information for this issue.

    >>I'm sorry.  I've only just had chance to look at your suggested code.  It appears to simply open a named Word Document from Access. <<

    The code sample above is a demo to help you understand how to automation Word application in other Office products and it also demos how to subscribe the events in other Office products.

    >>What we NOW want to be able to do, may well be impossible.  What we want to be able to do, is insert VBA code from Access into a WORD Document so that when WORD itself performs a Mail-Merge the inserted code executes from within WORD.  <<

    Yes, it is possible to insert VBA code from Access into Word document. And here is a sample for your reference, to run the code we need to add the Word object model referece and Microsoft Visual Basic for Application Extensiblity:

    Sub InsertCode()
    Dim doc As Word.document
    Set doc = Word.Application.Documents.Open("C:\Users\UserName\Desktop\Doc1.docm")
    AddModuleToProject "test1", doc
    AddProcedureToModule "test1", doc
    doc.Save
    End Sub
    
     Sub AddModuleToProject(moduleName As String, ByRef doc As Word.document)
            Dim VBProj As VBIDE.VBProject
            Dim VBComp As VBIDE.VBComponent
            
            Set VBProj = doc.VBProject
            Set VBComp = doc.VBProject.VBComponents.Add(vbext_ct_StdModule)
            VBComp.Name = moduleName
            
        End Sub
        
         Sub AddProcedureToModule(moduleName As String, ByRef doc As Word.document)
            Dim VBProj As VBIDE.VBProject
            Dim VBComp As VBIDE.VBComponent
            Dim CodeMod As VBIDE.CodeModule
            Dim LineNum As Long
            Const DQUOTE = """" ' one " character
    
            Set VBProj = doc.VBProject
            Set VBComp = VBProj.VBComponents(moduleName)
            Set CodeMod = VBComp.CodeModule
            
            With CodeMod
                LineNum = .CountOfLines + 1
                .InsertLines LineNum, "Public Sub HelloWord()"
                LineNum = LineNum + 1
                .InsertLines LineNum, "    MsgBox " & DQUOTE & "Hello World" & DQUOTE
                LineNum = LineNum + 1
                .InsertLines LineNum, "End Sub"
            End With
        End Sub

    >>If we HAVE to we can always add the code into the WORD Template.  The question is - DO WE HAVE TO?<<

    Did you mean inserting code to a Word template rather than Word document? In my option, if the users need to run in every document, insert into template is recommend.

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, November 28, 2014 9:38 AM
  • The problem with inserting code dynamically is that the Word user has to have allowed programmatic access to the VBA project object model (via the Options->Trust Center->Trust Center Settins...->Macro settings in (say) Word 2013). If you can ensure that your users have that set, you are probably OK.

    Otherwise, I just wonder whether the following suggestions may get you started on an approach that does put code in a .dotm (all the mail merge main document would need to be attached to that .dotm - otherwise, you can consider a template used as an Addin, but that introduces a different set of condierations).

    Assuming that Word is not detaching the data source if/when you open the Word document from your Access code (assuming that is what you are doing), then the mailmerge data source should already be attached, and you your application ought to be able to write the .Mailmerge.MailSubject and .MailAddress properties of the document. Otherwise, if the user has to manually re-attach the data source, it's not so obvious at what point the MailSubject (say) could be specified - in the Before Merge event is too late, I think.

    Anyway, the following changes made the .dotm approach worked for me, in the sense that the appropriate events fired. Even if this code structure works for you, you will probably need to do more, e.g. if you want to avoid problems if the user has two of these documents open at the same time. 

    In your .dotm's ThisDocument module, put

    Dim app As appEventClass
    Private Sub Document_Open()
    MsgBox "In mmeventcode1 document_open"
    Set app = New appEventClass
    Set app.m_WORDapplication = Word.Application
    ' You may need to track this differently now...
    app.m_b_WORDapplication_AlreadyOpen = True
    ' So this should show the Wizard in the document the user has just opened...
    ActiveDocument.MailMerge.ShowWizard 6
    End Sub

    Private Sub Document_Close()
    MsgBox "In mmeventcode1 document_close"
    If ActiveDocument.MailMerge.Destination = wdSendToEmail Then
      Set app.m_WORDapplication = Nothing
      Set app = Nothing
    End If
    End Sub

    Then in a CLass module called appEventClass, put the rest of your code, slightly modified. Not *that* important, but notice that I have used the Doc parameter passed to the routines rather than the ActiveDocument reference. 

        Public WithEvents m_WORDapplication As Application

        Public m_b_WORDapplication_AlreadyOpen As Boolean

        Dim m_s_EmailSubject As String
        Dim m_b_FirstRecord As Boolean

    Private Sub m_WORDapplication_MailMergeBeforeMerge(ByVal Doc As Document, ByVal StartRecord As Long, ByVal EndRecord As Long, Cancel As Boolean)
    MsgBox "In mmeventcode1 MMBM"

        If Doc.MailMerge.Destination = wdSendToEmail Then
            'Initialise the Module level variable m_b_FirstRecord
            'so that Sub m_WORDapplication_MailMergeBeforeRecordMerge will know it's dealing with the FirstRecord
            m_b_FirstRecord = True
        End If

    End Sub


    Private Sub m_WORDapplication_MailMergeBeforeRecordMerge(ByVal Doc As Document, Cancel As Boolean)
    '
    '   Written by: Brian McGuigan
    '           of: On2it Software Ltd
    '      Version: 1
    '        Dated: 26-Mar-14
    'First Used in: NEXT Version
    '       Status: Tested
    '
    '      Purpose: This Subroutine changes the ActiveDocument.MailMerge.MailSubject before each Record is merged.
    '
    '       Method: It does so by replacing any
    '                   ActiveDocument.MailMerge.DataSource.DataFields(i).Name
    '               it finds in the
    '                   .MailSubject
    '               delimited by <<.....>> with the corresponding
    '                   .DataSource.DataFields(i).Value

        Dim i_NumberOfMergeFields As Integer
        Dim i As Integer
    MsgBox "In mmeventcode1 MMBRM"

        With Doc.MailMerge

            If .Destination = wdSendToEmail Then

                If m_b_FirstRecord = True Then
                    'Remember .MailSubject complete with Mail-Merge Fields as originally entered with <<.....>>
                    m_s_EmailSubject = .MailSubject
                    m_b_FirstRecord = False
                Else
                    'Reset .MailSubject to so that it still contains the Mail-Merge Fields as entered with <<.....>>
                    .MailSubject = m_s_EmailSubject
                End If

                'Count Mail-Merge DataSource Fields in Document
                i_NumberOfMergeFields = .DataSource.DataFields.Count

                'Replace each Mail-Merge DataSource Field delimited with <<.....>> in .MailSubject
                For i = 1 To i_NumberOfMergeFields

                    .MailSubject = Replace( _
                        Expression:=.MailSubject, _
                        Find:="<<" & .DataSource.DataFields(i).Name & ">>", _
                        Replace:=.DataSource.DataFields(i).Value, _
                        Compare:=vbTextCompare)

                    'If there are no Merge-Fields left in .MailSubject Exit For loop
                    If InStr(1, .MailSubject, "<<") = 0 Then Exit For

                Next i

                m_b_FirstRecord = False

            End If

        End With

    End Sub


    Private Sub m_WORDapplication_MailMergeAfterMerge(ByVal Doc As Document, ByVal DocResult As Document)
    MsgBox "In mmeventcode1 MMAM"
        If Doc.MailMerge.Destination = wdSendToEmail Then
          Doc.MailMerge.MailSubject = m_s_EmailSubject
        End If
    End Sub

                                                                                                                            

    Peter Jamieson

    Friday, November 28, 2014 3:49 PM
  • Hi Peter,

    Thanks for your reply.  I didn’t think of the Trust Centre implications.  You’re quite right of course.  I really think many users would baulk at messing around with their Trust Centre Settings.  If they were in our Organisation, it would not be too bad, but we're talking staff in our client's businesses here.

    The way our application currently works.  Is that users start with a Word Template containing ‘MacroButtons’ with certain pre-defined names and perhaps ‘Mail-Merge Fields’.  Our application is told where these are stored and what else should be done when they are used: Categories to be assigned, Reminders to be set, Tasks to be created and so on. 

    The same Templates are used by everyone in the organisation to originate both single E-mails, Faxes and Letters, as well as Mail-Merges using exactly the same documents.  (This avoids having to maintain multiple versions of the same Template.)

    The user starts by selecting who he wants to send correspondence to and the Template to be used.  Our application copies the Template into a Document.  It then replaces the ‘MacroButtons’ with Salutation and Signature information for each User so that everyone in the organisation signs documents in a standard way.  If the Document is going to multiple recipients a Mail-Merge Data Source is attached.  The Document is then opened and control is passed to the User.  Our application simply waits until the document closes. 

    We already have a ‘Master’ Document Template that we distribute with the application, with all the appropriate ‘MacroButton’ Fields in it.  We then suggest to Users that they should produce their own ‘Master’ Template by copying ours and formatting it to their own needs.  From there on they can produce their own individual Templates by copying their ‘Master’ and adding the appropriate boiler-plate text. 

    We could simply add the necessary code to our ‘Master’ Document Template so that it will get distributed to all their Templates – provided they don’t save their templates as a .dot, without the code.  I don’t like relying on User’s doing the right thing, as they have a nasty habit of doing the opposite - which is why I was looking to do it for them.  Well I suppose that’s what User Manuals and training is for – if only they’d read them.  L

    The problem is there is no fail-safe here.  For if the user has eliminated the background code in the Template and they put “<<First Name>>” in the Subject, then it won’t be substituted with “Peter” or whatever during the Mail-Merge.  Yes, they can and SHOULD test it first, but will they? 

    Nevertheless, I still think I prefer this to asking User to mess around with their Trust Centre settings.

    Thanks for your help.  I'll post the code when I've got it going - together with an explanation of why we chose to do it this way.

    Thanks Again

    Brian

    P.S.  If you want to know what application we've been talking about, see www.GEMnetworking.com

    Saturday, November 29, 2014 2:35 AM