In the code below, XFERDATA is the named range within one of the worksheets in the excel workbook where the code is located. Suitable syntax to tell word to use the data source that is already open. My problem lies in that when the code gets to the point when it defines the data source for the merge, it tries to open it, but finds that it is already open (because that is where the code is running from!) Extensive research has not found a The code for the mail merge primarily by recording a macro in Word and then adapting it to run on excel. I cannot therefore set the references to Word because it is different for each machine. I am using late binding becauseĮxcel and word have to run on machines that use different versions of Office (20), but all have to save back to the Office 2013 machine. The data is located in a named range within one worksheet of the open workbook. Here is an example: ItemĪs Word processes each record of the data source, the value of the OldCat data field is the same as the contents of the Category data field in the previous record.I have an Excel workbook using VBA to prepare data for a mail merge to word and then to run the merge from within the Excel procedure. One possible workaround to this shortcoming-if you are using an Excel worksheet as your data source-is to simply copy the controlling field (column) to another column, and then offset it by one row. It would be very nice to compare the contents of a data field in the current record with the contents of the same data field in the previous record, but Word will unfortunately not allow it. You cannot use Word's conditional mail-merge fields to compare values in any record other than the current one. Use this field when you want to compare the contents of a data field to a value, and then ignore the current data record if the comparison is true.
Use this field if you want to compare the contents of a data field to a value, and then jump to the next record if the comparison is true. This field is equivalent to the construct of the same name used in many programming languages. Use this field if you want to do a comparison between a data field and a value, and then take some action based on the comparison. The three fields you can use for conditional processing are as follows: These types of fields can be easily inserted by clicking on the Insert Word Field drop-down list on the Mail Merge toolbar.
Word also includes special fields that allow you to conditionally control how Word does the merging. When using Word's mail merge feature, you are not limited to using only the actual data fields when putting together your merge document.