I made some minor changes and am running the code in a DocumentOpen
event, and yes, with some types of data source it does appear to be very
slow. However, it's not obvious what the common factor is - so far I
have tried
a. an Outlook source (i.e. connecting from Word. That would use the
Jet/ACE OLE DB provider and the Outlook/Exchange IISAM. Slow.
b. More or less the same data in a .csv file. In this case, Word would
use the same provider but the Text IISAM (may not mean anything to you).
Slow.
Either way, I see the following message, which doesn't mean much to me
but may mean something to you:
A first chance exception of type
'System.Runtime.InteropServices.SEHException' occurred in WordAddIn3.DLL
c. More or less the same data in a .xls file. In this case, Word would
probably use the same provider but the Excel IISAM. Much quicker!
Not really enugh to draw much of a conclusion except that the type of
data source does seem to make a significant different.
Peter Jamieson
http://tips.pjmsn.me.uk
On 05/03/2010 16:33, amr wrote:
[i]
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[4] = (fieldCount= (int)indexCity) ?
fields.get_Item(ref indexCity).Value : "";
dataSrc.ActiveRecord =
Microsoft.Office.Interop.Word.WdMailMergeActiveRec ord.wdNextDataSourceRecord;
}
}
}