T
tanguy
Hi,
I developed a mail merge program in C# but when I execute the merging (to a
new document), Word appears without any toolbar, menu or statusbar, but
mailmerge worked fine
What happened?
Here is my code:
public void ExecuteMailMerge(string contactids, System.Windows.Forms.Label
displayInfo)
{
wordApp.Application word = null;
object missing = System.Reflection.Missing.Value;
object oTrue = true;
object oFalse = false;
try
{
//Create Word Application
word = new wordApp.ApplicationClass();
object wordTemplateName = templateFileName;
//Open Word template
wordApp.Document doc = word.Documents.Open(ref wordTemplateName,ref
missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref
missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref
missing,ref missing,ref missing);
wordApp.MailMerge wrdMailMerge = doc.MailMerge;
//Create DataSource
CreateMailMergeDataFile(word,doc,contactids);
wrdMailMerge.Destination =
wordApp.WdMailMergeDestination.wdSendToNewDocument;
wrdMailMerge.Execute(ref oFalse);
word.Visible = true;
//Close Word Template
doc.Saved = true;
doc.Close(ref oFalse,ref missing,ref missing);
//Flush ressources
wrdMailMerge = null;
doc = null;
//Delete DataSource
System.IO.File.Delete("C:\\datasource.xml");
}
catch(Exception erreur)
{
word.Quit(ref oFalse,ref oFalse,ref oFalse);
throw new Exception(erreur.Message);
}
}
Thx
I developed a mail merge program in C# but when I execute the merging (to a
new document), Word appears without any toolbar, menu or statusbar, but
mailmerge worked fine
What happened?
Here is my code:
public void ExecuteMailMerge(string contactids, System.Windows.Forms.Label
displayInfo)
{
wordApp.Application word = null;
object missing = System.Reflection.Missing.Value;
object oTrue = true;
object oFalse = false;
try
{
//Create Word Application
word = new wordApp.ApplicationClass();
object wordTemplateName = templateFileName;
//Open Word template
wordApp.Document doc = word.Documents.Open(ref wordTemplateName,ref
missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref
missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref
missing,ref missing,ref missing);
wordApp.MailMerge wrdMailMerge = doc.MailMerge;
//Create DataSource
CreateMailMergeDataFile(word,doc,contactids);
wrdMailMerge.Destination =
wordApp.WdMailMergeDestination.wdSendToNewDocument;
wrdMailMerge.Execute(ref oFalse);
word.Visible = true;
//Close Word Template
doc.Saved = true;
doc.Close(ref oFalse,ref missing,ref missing);
//Flush ressources
wrdMailMerge = null;
doc = null;
//Delete DataSource
System.IO.File.Delete("C:\\datasource.xml");
}
catch(Exception erreur)
{
word.Quit(ref oFalse,ref oFalse,ref oFalse);
throw new Exception(erreur.Message);
}
}
Thx