View Single Post
  #5   Report Post  
Posted to microsoft.public.word.mailmerge.fields
AMR AMR is offline
external usenet poster
 
Posts: 6
Default MailMergeDataSource iteration extremly slow


A simple callback for a ribbon button is below. Before you press the button,
you have to load a source. I loaded my outlook contacts.

public void TestDataSource(Microsoft.Office.Core.IRibbonContro l ribbon) {

Word.MailMergeDataSource dataSrc =
Application.ActiveDocument.MailMerge.DataSource

int count = dataSrc.RecordCount;

if (count 0) {
string[][] addressList = new string[count][5];

Word.MailMergeDataFields fields = dataSrc.DataFields;

object indexLastname = 2;
object indexFirstname = 1;
object indexCompany = 4;
object indexStreet = 8;
object indexZip = 11;
object indexCity = 9;

object index = 0;
for (int i = 0; i count; i++) {
int fieldCount = fields.Count;

addressList[i][0] = (fieldCount = (int)indexFirstname) ?
fields.get_Item(ref indexFirstname).Value + " " + fields.get_Item(ref
indexLastname).Value : "";
addressList[i][1] = (fieldCount = (int)indexCompany) ?
fields.get_Item(ref indexCompany).Value : "";
addressList[i][2] = (fieldCount = (int)indexStreet) ?
fields.get_Item(ref indexStreet).Value : "";
addressList[i][3] = (fieldCount = (int)indexZip) ?
fields.get_Item(ref indexZip).Value : "";
addressList[i][4] = (fieldCount = (int)indexCity) ?
fields.get_Item(ref indexCity).Value : "";

dataSrc.ActiveRecord =
Microsoft.Office.Interop.Word.WdMailMergeActiveRec ord.wdNextDataSourceRecord;
}
}

}