I need to create a method that finds a word and replace it for another. I
add at the end of this post the code. My problem is that every time I try to
run it, it gives me an error either stack over flow or "stub" something. The
error ocurr only when I try to acces the Replacement property. Most of my
code is from a person who told me that this code was running in his
computer.
Is it right? What do I need to make run?
Please help!
private void button1_Click(object sender, System.EventArgs e)
{
object readOnly = false;
object isVisible = true;
object missingValue = Type.Missing;
object replaceAll = Microsoft.Office.Interop.Word.WdReplace.wdReplaceA ll;
string currentDate = DateTime.Now.ToString();
object fileName = @"C:\A Document.doc";
object falseCond = false;
object empty = "";
object nullObj = null;
object objFormat =
Microsoft.Office.Interop.Word.WdOpenFormat.wdOpenF ormatAuto;
Microsoft.Office.Interop.Word.ApplicationClass wordApp = new
Microsoft.Office.Interop.Word.ApplicationClass();
wordApp.Visible = true;
Microsoft.Office.Interop.Word.Document myDoc = wordApp.Documents.Open(ref
fileName,
ref missingValue, ref readOnly, ref missingValue, ref missingValue,
ref missingValue, ref missingValue, ref missingValue, ref missingValue,
ref missingValue, ref missingValue, ref isVisible, ref missingValue,
ref missingValue, ref missingValue);
try
{
wordApp.Application.Selection.Find.ClearFormatting ();
// Full name search/replace
myDoc.Application.Selection.Find.Text = "Historia";
myDoc.Application.Selection.Find.Replacement.Text = "Futuro";
myDoc.Application.Selection.Find.Execute(ref missingValue,
ref missingValue, ref missingValue, ref missingValue,
ref missingValue, ref missingValue, ref missingValue,
ref missingValue, ref missingValue, ref missingValue,
ref replaceAll, ref missingValue, ref missingValue,
ref missingValue, ref missingValue);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message );
}
}
}