Below i attached my project, where i want to open a document file(which is also attached) with read and write access, by clicking open button and "EditDocument" form will also open. whatever i will write in textbox1 in "EditDocument" form, it will replace it with "Name" in word document.
textbox2.text will replace it with "Address" in word document.
textbox3.text will replace it with "Qualification" in word document.
"It will act like find and replace option in office2007".
can onyone help me on this problem.
Loading

Iftikar HussainPosted Aug 6, 2013, 2:20 AM
I have modified your project, please find the attached.
You need to set the template path
Regards,
Iftikar
Iftikar HussainPosted Aug 6, 2013, 4:47 AM
Regards,
Iftikar
Posted Aug 6, 2013, 4:16 AM
doc.SaveAs("MyFile.doc", ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
Preeti AgrawallaPosted Aug 6, 2013, 4:07 AM
Preeti AgrawallaPosted Aug 6, 2013, 4:03 AM
Preeti AgrawallaPosted Aug 6, 2013, 3:47 AM
Iftikar HussainPosted Aug 6, 2013, 3:44 AM
Regards,
Iftikar
Posted Aug 6, 2013, 3:41 AM
Posted Aug 6, 2013, 3:40 AM
Document adoc = WordApp.Documents.Add(ref missing, ref missing, ref missing, ref missing);
Range rng = adoc.Range(ref start1, ref missing);
Preeti AgrawallaPosted Aug 6, 2013, 3:36 AM
Preeti AgrawallaPosted Aug 6, 2013, 3:31 AM
Iftikar, this error i am getting.
Posted Aug 6, 2013, 2:18 AM
it will open in a separate process in that you can't do Find & replace.
Instead of that, launch word in your application, do the find & replace.
The code looks something similar to this.
It will write some text into the word document and you can try for find & replace here.
private void button1_Click(object sender, EventArgs e)
{
object missing = System.Reflection.Missing.Value;
object Visible=true;
object start1 = 0;
object end1 = 0;
ApplicationClass WordApp = new ApplicationClass();
Document adoc = WordApp.Documents.Add(ref missing, ref missing, ref missing, ref missing);
Range rng = adoc.Range(ref start1, ref missing);
try
{
rng.Font.Name = "Georgia";
rng.InsertAfter("Hello World!");
object filename = "YOUR DOCUMENT PATH";
adoc.SaveAs(ref filename, 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.Visible = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}