Microsoft.Office.Interop.Word MailMerge POPUP for Sheet1$ and Filter on column

  • Thread starter Thread starter MikeInNorthbrook
  • Start date Start date
M

MikeInNorthbrook

Guest
I can't seem to suppress that message box Select Table -> Sheet1$

Also does any1 know how to filter on a column in the Excel sheet and say only merge records where column P = ABC ?

Thx in advance.


Microsoft.Office.Interop.Word.Application wordapp = new Microsoft.Office.Interop.Word.Application();
wordapp.Visible = false;
wordapp.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;

object filename = @"H:\Billing\BillsByDueDate\MarketingInvoices3.doc";
object objTrue = true;
object objFalse = false;
object objMiss = Type.Missing;
Microsoft.Office.Interop.Word.Document myMergeDocument;

//Open the Template file
myMergeDocument = wordapp.Documents.Open(ref filename, ref objMiss, ref objMiss, ref objMiss, ref objMiss, ref objMiss, ref objMiss, ref objMiss, ref objMiss, ref objMiss, ref objMiss, ref objMiss, ref objMiss, ref objMiss, ref objMiss, ref objMiss);
myMergeDocument.Select();

//Open the data source
object format = Microsoft.Office.Interop.Word.WdOpenFormat.wdOpenFormatText;
//myMergeDocument.MailMerge.OpenDataSource(@"H:\Billing\BillsByDueDate\InvoiceList.xlsx", ref format, ref objFalse, ref objMiss, ref objTrue, ref objFalse, ref objMiss, ref objMiss, ref objMiss, ref objMiss, ref objMiss, ref objMiss, ref objMiss, ref objMiss, ref objMiss, ref objMiss);
myMergeDocument.MailMerge.OpenDataSource(@"H:\Billing\BillsByDueDate\InvoiceList3.xls", ref format, ref objFalse, ref objMiss, ref objTrue, ref objFalse, ref objMiss, ref objMiss, ref objMiss, ref objMiss, ref objMiss, "Select * from Sheet1$", ref objMiss, ref objMiss, ref objMiss, ref objMiss); //WdMergeSubType.wdMergeSubTypeWord2000

//Perform the Mail Merge!!!

//if (DIRECT_PRINT)
// myMergeDocument.MailMerge.Destination = Microsoft.Office.Interop.Word.WdMailMergeDestination.wdSendToPrinter;
//else
myMergeDocument.MailMerge.Destination = Microsoft.Office.Interop.Word.WdMailMergeDestination.wdSendToNewDocument;

myMergeDocument.MailMerge.SuppressBlankLines = true;
myMergeDocument.MailMerge.DataSource.FirstRecord = (int)Microsoft.Office.Interop.Word.WdMailMergeDefaultRecord.wdDefaultFirstRecord;
myMergeDocument.MailMerge.DataSource.LastRecord = (int)Microsoft.Office.Interop.Word.WdMailMergeDefaultRecord.wdDefaultLastRecord;
myMergeDocument.MailMerge.Execute(ref objFalse);



//Close the template document.
myMergeDocument.Close();

//Print the derived document.

wordapp.Visible = true;
wordapp.ShowMe();
return;

Continue reading...
 
Back
Top