View Single Post
 
Old 09-05-2014, 08:59 AM
taylorblu taylorblu is offline Windows 8 Office 2013
Novice
 
Join Date: Sep 2014
Posts: 2
taylorblu is on a distinguished road
Default VBA to automatically sort items based on Mail Merge field

I have a quote mail merge template that contains products. In the source, Dynamics CRM, each product contains a sequence number (field). The user is able to modify the order of the products and CRM will adjust the sequence number accordingly. The problem is when the quote is printed, the order of the products always revert back to the original order in which they were entered and not by the sequence number.

In Word, you can manually set the order by opening the 'Edit Recipient List', find the quote_product_sequence_number field column, and sort. But I need this to be automated.

I tried recording a macro as I walked through the manual steps, but the macro does not record anything when the 'Edit Recipient List' dialog box is open.

I tried adding this code ... but I get an 'object required' error.
Sub SequenceOrder()

' Sort by Sequence
sequence = ActiveDocument.MailMerge.DataSource.DataFields("Qu ote_Product_Sequence_Number").Value
sequence.Value.Sort SortOrder:=wdSortOrderAscending

End Sub

Any ideas?
Reply With Quote