#1
|
|||
|
|||
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? |
#2
|
||||
|
||||
AFAIK, if you set the sort order via the filters and save the mailmerge main document that way, the same sort order should be retained when you next open the mailmerge main document. You shouldn't need any code for this.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
||||
|
||||
Cross-posted at: http://answers.microsoft.com/en-us/o...5-80eb6a546396
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#4
|
|||
|
|||
I thought so too and tried it, but the sort doesn't maintain when the template it run again. I think it refreshes with the new list of recipients.
|
Tags |
mail merge, vba in microsoft word |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Mail merge how to link mail merge field value to a column heading | dsummers | Mail Merge | 1 | 05-08-2014 02:59 PM |
How to ignore a mail merge field if the field is blank | redzan | Mail Merge | 1 | 05-16-2013 08:34 AM |
Automatically split Mail Merge based on number of pages | SaneMan | Mail Merge | 1 | 12-03-2011 01:11 AM |
dynamic charts based on mail merge fields | jwajehee | Mail Merge | 0 | 10-05-2011 09:47 AM |
Selecting merge field based on whether or not text is present | amym | Mail Merge | 1 | 12-07-2010 05:14 AM |